java Camel动态路由器修改消息不工作
弹簧配置:
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="kafka:127.0.0.1:9092?topic=test1&zookeeperHost=127.0.0.1&zookeeperPort=2181&groupId=group1&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" />
滑移法:
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;
}
我尝试了两种方法来修改消息体,但都不起作用。如何修改邮件正文?使用处理器
# 1 楼答案
您不能在动态路由器(slip)中修改消息。您需要使用消息转换EIP来实现这一点,比如调用bean/处理器等