LibraryToggle FramesPrintFeedback

The wire tap pattern, as shown in Figure 19.1, enables you to route a copy of the message to a separate tap location, while the original message is forwarded to the ultimate destination.

You can define a wiretap with a new exchange instance by setting the copy flag to false (the default is true). In this case, an initially empty exchange is created for the wiretap.

For example, to create a new exchange instance using the processor approach:

    .wireTap("direct:foo", false, new Processor() {
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody("Bye World");
            exchange.getIn().setHeader("foo", "bar");


Where the second wireTap argument sets the copy flag to false, indicating that the original exchange is not copied and an empty exchange is created instead.

To create a new exchange instance using the expression approach:

    .wireTap("direct:foo", false, constant("Bye World"))


Using the Spring XML extensions, you can indicate that a new exchange is to be created by setting the wireTap element's copy attribute to false.

To create a new exchange instance using the processor approach, where the processorRef attribute references a Spring bean with the myProcessor ID, as follows:

    <from uri="direct:start2"/>
    <wireTap uri="direct:foo" processorRef="myProcessor" copy="false"/>
    <to uri="mock:result"/>

And to create a new exchange instance using the expression approach:

    <from uri="direct:start"/>
    <wireTap uri="direct:foo" copy="false">
        <body><constant>Bye World</constant></body>
    <to uri="mock:result"/>

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 errorHandlerRef="errorHandler" streamCache="false" id="camel" xmlns="">
        <from uri="seda:a"/>
            <to uri="seda:tap"/>
            <to uri="seda:b"/>
Comments powered by Disqus
loading table of contents...