Chapter 2. Basic Principles of Route Building
2.1. Pipeline Processing
ls | moreis an example of a command that pipes a directory listing,
ls, to the page-scrolling utility,
more. The basic idea of a pipeline is that the output of one command is 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.
org.apache.camel.Processorinterface. In other words, processors make up the basic building blocks of a DSL route. For example, DSL commands such as
to()all represent processors. When considering how processors connect together to build up a route, it is important to distinguish two different processing approaches.
nullin this case.
Figure 2.1. Processor Modifying an In Message
setHeader()command that modifies the current In message by adding (or modifying) the
from("activemq:orderQueue") .setHeader("BillingSystem", xpath("/order/billingSystem")) .to("activemq:billingQueue");
Figure 2.2. Processor Creating an Out Message
transform()command that creates an Out message with a message body containing the string,
from("activemq:orderQueue") .transform(constant("DummyBody")) .to("activemq:billingQueue");
constant("DummyBody")represents a constant expression. You cannot pass the string,
DummyBody, directly, because the argument to
transform()must be an expression type.
Pipeline for InOnly exchanges
Figure 2.3. Sample Pipeline for InOnly Exchanges
userdataQueuequeue, pipes the message through a Velocity template (to produce a customer address in text format), and then sends the resulting text address to the queue,
from("activemq:userdataQueue") .to(ExchangePattern.InOut, "velocity:file:AdressTemplate.vm") .to("activemq:envelopeAddresses");
velocity:file:AdressTemplate.vm, specifies the location of a Velocity template file,
file:AdressTemplate.vm, in the file system. The
to()command changes the exchange pattern to InOut before sending the exchange to the Velocity endpoint and then changes it back to InOnly afterwards. For more details of the Velocity endpoint, see Velocity in the Apache Camel Component Reference Guide.
Pipeline for InOut exchanges
Figure 2.4. Sample Pipeline for InOut Exchanges
from("jetty:http://localhost:8080/foo") .to("cxf:bean:addAccountDetails") .to("cxf:bean:getCreditRating") .to("cxf:bean:processTransaction");
cxf:bean:processTransaction. The final Web service,
processTransaction, generates a response (Out message) that is sent back through the JETTY endpoint.
from("jetty:http://localhost:8080/foo") .pipeline("cxf:bean:addAccountDetails", "cxf:bean:getCreditRating", "cxf:bean:processTransaction");
Pipeline for InOptionalOut exchanges
nullOut message is copied to the In message of the next node in the pipeline. By contrast, in the case of an InOut exchange, a
nullOut message is discarded and the original In message from the current node would be copied to the In message of the next node instead.