Wire TapThe Wire Tap from the EIP patterns allows you to route messages to a separate tap location while it is forwarded to the ultimate destination.
WireTap nodeAvailable as of Camel 2.0 In Camel 2.0 we have introduced a new wireTap node for properly doing wire taps. Camel will copy the original Exchange and set its Exchange Pattern to InOnly as we want the tapped Exchange to be sent as a fire and forget style. The tapped Exchange is then send in a separate thread so it can run in parallel with the original We have extended the wireTap to support two flavors when tapping an Exchange
Sending a copy (traditional wire tap)Using the Fluent Builders from("direct:start") .to("log:foo") .wireTap("direct:tap") .to("mock:result"); Using the Spring XML Extensions <route> <from uri="direct:start"/> <to uri="log:foo"/> <wireTap uri="direct:tap"/> <to uri="mock:result"/> </route> Sending a new ExchangeUsing the Fluent Builders Below is the processor variation shown: from("direct:start") .wireTap("direct:foo", new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody("Bye World"); exchange.getIn().setHeader("foo", "bar"); } }).to("mock:result"); from("direct:foo").to("mock:foo"); And the Expression variation: from("direct:start") .wireTap("direct:foo", constant("Bye World")) .to("mock:result"); from("direct:foo").to("mock:foo"); Using the Spring XML Extensions <route> <from uri="direct:start"/> <wireTap uri="direct:foo"> <body><constant>Bye World</constant></body> </wireTap> <to uri="mock:result"/> </route> And the Expression variation, where the expression is defined in the body tag: <route> <from uri="direct:start2"/> <wireTap uri="direct:foo" processorRef="myProcessor"/> <to uri="mock:result"/> </route> Camel 1.xThe following example shows how to route a request from an input queue:a endpoint to the wire tap location queue:tap it is received by queue:b Using the Fluent Builders RouteBuilder builder = new RouteBuilder() { public void configure() { errorHandler(deadLetterChannel("mock:error")); from("seda:a").multicast().to("seda:tap", "seda:b"); } }; Using the Spring XML Extensions <camelContext errorHandlerRef="errorHandler" streamCache="false" id="camel" xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="seda:a"/> <multicast> <to uri="seda:tap"/> <to uri="seda:b"/> </multicast> </route> </camelContext> Further ExampleFor another example of this pattern in use you could look at the wire tap test case. Using This PatternIf you would like to use this EIP Pattern then please read the Getting Started, you may also find the Architecture useful particularly the description of Endpoint and URIs. Then you could try out some of the Examples first before trying this pattern out. |
