Message Router - 6.3

Talend ESB Mediation Developer Guide

EnrichVersion
6.3
EnrichProdName
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
task
Design and Development
EnrichPlatform
Talend ESB

The Message Router from the EIP patterns allows you to consume from an input destination, evaluate some predicate then choose the right output destination.

The following example shows how to route a request from an input queue:a endpoint to either queue:b, queue:c or queue:d depending on the evaluation of various Predicate expressions

Using the Fluent Builders

RouteBuilder builder = new RouteBuilder() {
    public void configure() {
        errorHandler(deadLetterChannel("mock:error"));

        from("seda:a")
            .choice()
                .when(header("foo").isEqualTo("bar"))
                    .to("seda:b")
                .when(header("foo").isEqualTo("cheese"))
                    .to("seda:c")
                .otherwise()
                    .to("seda:d");
    }
};

Here is another example of using a bean to define the filter behavior

from("direct:start")
.filter().method(MyBean.class, "isGoldCustomer").to("mock:result").end()
.to("mock:end");

public static class MyBean {
   public boolean isGoldCustomer(@Header("level") String level) {
      return level.equals("gold");
   }
}

Using the Spring XML Extensions

<camelContext errorHandlerRef="errorHandler" 
    xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="seda:a"/>
        <choice>
            <when>
                <xpath>$foo = 'bar'</xpath>
                <to uri="seda:b"/>
            </when>
            <when>
                <xpath>$foo = 'cheese'</xpath>
                <to uri="seda:c"/>
            </when>
            <otherwise>
                <to uri="seda:d"/>
            </otherwise>
        </choice>
    </route>
</camelContext>

Note if you use a choice without adding an otherwise, any unmatched exchanges will be dropped by default.