Brutal_JL
Brutal_JL

Reputation: 2847

Camel dynamic router modify message don't work

Spring configuration:

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="kafka:127.0.0.1:9092?topic=test1&amp;zookeeperHost=127.0.0.1&amp;zookeeperPort=2181&amp;groupId=group1&amp;serializerClass=kafka.serializer.StringEncoder"/>
        <dynamicRouter>
            <!-- use a method call on a bean as dynamic router -->
            <method ref="compositorSlip" method="slip"/>
        </dynamicRouter>
    </route>
</camelContext>
<bean id="compositorSlip" class="com.maxent.routingcenter.DynamicRouterTest" />

slip method:

public String slip(Exchange exchange, @Header(Exchange.SLIP_ENDPOINT) String previous) {
    // just route one time, return null means to end.
    if(previous != null){
        return null;
    }
    // I've tried two ways to modify the message body, but they both didn't work.
    exchange.getOut().setBody("message modified!!!!!", String.class);
    exchange.getIn().setBody("message modified!!!!!", String.class);
    if (i++ % 2 == 0) {
        return "file://test";
    }
    return null;
}

I've tried two ways to modify the message body, but they both didn't work. How can I modify the message body? Use the Processor?

Upvotes: 0

Views: 670

Answers (1)

Claus Ibsen
Claus Ibsen

Reputation: 55525

You cannot modify the message in the dynamic router (slip). You need to use message transformation EIP for that such as calling a bean / processor etc.

Upvotes: 1

Related Questions