Pipeline Processing (Route Definition)

Pipeline Processing

The concept of pipelining is the predominant scenario for connecting nodes in a route definition. The basic idea of a pipeline is that the output of one command is then fed into the input of the next. The natural analogy in the case of a route is for the Out message from one processor to be copied to the In message of the next processor.

Processor Nodes

Every node in a route, with the exception of the initial endpoint, is a processor, in this situation they inherit from the org.apache.camel.Processor interface. Thus, processors make up the basic building blocks of a DSL route.

1.1 Modifying an In Message

 

1.2 Creates an Out Message

Pipeline with InOnly Exchange

In the following example, Processor A acts by modifying the In message, while processors B and C create an Out message and the route builder links the processors together. In this situation, processors B and C are linked together in the form of a pipeline: which means that processor B’s Out message is moved to the In message before feeding the exchange into processor C, and processor C’s Out message is moved to the In message before feeding the exchange into the producer endpoint. Thus the processors' outputs and inputs are joined into a continuous pipeline:

NOTE: Apache Camel employs the pipeline pattern by default, so you do not need to use any special syntax to create a pipeline in your routes.

Pipeline with InOut Exchange

The illustration below is an example of a processor pipeline for InOut exchanges, which you typically use to support remote procedure call (RPC) semantics. In this situation, the Processors A, B, and C are linked together in the form of a pipeline, with the output of each processor being fed into the input of the next. Upon conclusion, the final Out message produced by the producer endpoint is transmitted back to the consumer endpoint, thus providing the response to the original request.

NOTE: To support the InOut exchange pattern, it is vitally important that the last node in the route (whether a producer endpoint or some other processor) creates an Out message. If not, then any client that connects to the consumer endpoint would hang as it waits indefinitely for a reply message.