LibraryLink ToToggle FramesPrintFeedback

Processing Models

Before implementing a processor, you need to consider how the processor will fit into a FUSE Mediation Router route. There are two basic ways to create routes:

Pipelining is the preferred method for constructing routes. However, you can accomplish the same routing functionality using either method.

The pipelining model describes the way in which processors are arranged in Pipes and Filters in Implementing Enterprise Integration Patterns. Pipelining is the most common way to process a sequence of endpoints (a producer endpoint is just a special type of processor). When the processors are arranged in this way, the exchange's In and Out messages are processed as shown in Figure 2.1.


The processors in the pipeline look like services, where the In message is analogous to a request, and the Out message is analogous to a reply. In fact, in a realistic pipeline, the nodes in the pipeline are often implemented by Web service endpoints, such as the CXF component.

For example, Example 2.1 shows a Java DSL pipeline constructed from a sequence of two processors, ProcessorA, ProcessorB, and a producer endpoint, TargetURI.


An alternative paradigm for linking together the nodes of a route is interceptor chaining, where a processor in the route processes the exchange both before and after dispatching the exchange to the next processor in the chain. This style of processing is also supported by FUSE Mediation Router, but it is not the usual approach to use. Figure 2.2 shows an example of an interceptor processor that implements a custom encryption algorithm.


In this example, incoming messages are encrypted in a custom format. The interceptor first decrypts the In message, then dispatches it to the Web services endpoint, cxf:bean:processTxn, and finally, the reply (Out message) is encrypted using the custom format, before being sent back through the consumer endpoint. Using the interceptor chaining approach, therefore, a single interceptor instance can modify both the request and the response.

For example, if you want to define a route with an HTTP port that services incoming requests encoded using custom encryption, you can define a route like the following:

from("jetty:http://localhost:8080/foo")
    .intercept(new MyDecryptEncryptInterceptor())
    .to("cxf:bean:processTxn");

Where the class, MyDecryptEncryptInterceptor, is implemented by inheriting from the class, org.apache.camel.processor.DelegateProcessor.

Although it is possible to implement encryption using an interceptor processor, this is not a common way of programming in FUSE Mediation Router. A more typical approach is shown in Figure 2.3.


In this example, the encryption functionality is implemented in a separate processor from the decryption functionality. The resulting processor pipeline is semantically equivalent to the original interceptor chain shown in Figure 2.2. One slight complication of the pipeline route is that it requires the addition of a transform processor at the end of the route to copy the In message to the Out message and making the reply message available to the HTTP consumer endpoint. An alternative solution to this problem is to implement the encrypt processor so that it creates an Out message directly.

To implement the pipeline approach shown in Figure 2.3, you can define a route similar to Example 2.2.


The final processor node, transform(body()), has the effect of copying the In message to the Out message (the In message body is copied explicitly and the In message headers are copied implicitly).