Wire Tap has been edited by Claus Ibsen (Mar 24, 2009).

(View changes)

Content:

Wire Tap

The 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 node

Available 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

  • send a copy of the original Exchange (the traditional wire tap)
  • send a new Exchange, allowing you to populate the Exchange beforehand

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 Exchange

Using the Fluent Builders
Camel supports either a processor or an _expression_ to populate the new Exchange. Using processor gives you full power how the Exchange is populated as you can set properties, headers etc. The _expression_ can only be used to set the IN body.

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
The processor variation, notice we use a processorRef attribute to refer to a spring bean with this id:

<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.x

The 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() {
        from("seda:a").multicast().to("seda:tap", "seda:b");
    }
};

Using the Spring XML Extensions

<camelContext 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 Example

For another example of this pattern in use you could look at the wire tap test case.

Using This Pattern

If 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.

Reply via email to