我有CamelConfiguration
配置15 Routes
。
public class CamelRoutesConf extends CamelConfiguration {
@Override
public List<RouteBuilder> configure() {
List<RouteBuilder> routes = super.routes();
routes.forEach(router -> {
router.onException(Exception.class).delay(5000);
});
return routes;
}
}
我想要实现的目标是检查路由中每个传入的Message
(exchange.getHeaders()
)的标头,如果它不存在则添加标头。< / p>
我可以在每个Processor
内使用RouteBuilder
来实现这一点。实施例
public class ArtistHiredRouteBuilder extends RouteBuilder {
@Override
public void configure(){
from(incomingArtistsQ)
.process(new Processor(){
public void process(Exchange exchange){
exchange.getIn().setHeader("JMSCorrelationId", randomNumberOfLength10());
}
})
.to(outgoingArtistsQ)
}
目的是在所有交换消息之间使用相同的id,以便以后更容易将它们联系起来。
那么,是否有一种Camel方式在CamelConfiguration#configure
中执行此操作,以便它适用于所有Route
。
我期望拦截如下。
public class CamelRoutesConf extends CamelConfiguration {
@Override
public List<RouteBuilder> configure() {
List<RouteBuilder> routes = super.routes();
routes.forEach(router -> {
router.interceptFrom().process(headerProcessor)
router.onException(Exception.class).delay(5000);
});
}
}
它会被拦截,但似乎不会继续.to()
RouteBuilder
{/ 1}}。
http://camel.apache.org/intercept.html
http://www.davsclaus.com/2009/05/on-road-to-camel-20-interceptors-round.html
答案 0 :(得分:1)
您可以使用interceptFrom()子句为所有路由设置标头值
// intercept all incoming routes and do something...
interceptFrom().setHeader(JMSCorrelationId", randomNumberOfLength10());