Apache camel 在Camel中拦截交换
假设我的路线如下Apache camel 在Camel中拦截交换,apache-camel,camel-ftp,Apache Camel,Camel Ftp,假设我的路线如下 from("direct:A") .process(new ProcessA()) .setHeader(Exchange.HTTP_METHOD, "get") .recipientList( simple(httpUri + header("doc_id")), "false") .process(new ProcessB()) .to("direct:B"); 在上面的路径httpUri=http4://localhost:25600中。现在我正试图
from("direct:A")
.process(new ProcessA())
.setHeader(Exchange.HTTP_METHOD, "get")
.recipientList( simple(httpUri + header("doc_id")), "false")
.process(new ProcessB())
.to("direct:B");
在上面的路径httpUri=http4://localhost:25600中。现在我正试图截取以下消息
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("http4*")
.skipSendToOriginalEndpoint()
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
//TODO
}
});
}
});
这里的问题是,即使存在skipSendToOriginalEndpoint,交换也没有被拦截,上下文实际上正在尝试与httpUri主机建立连接
如果代码中有任何错误,请告诉我。提前感谢。您使用的是动态路由,这意味着在定义时不知道端点。因此,您将无法基于http端点进行拦截 我要做的是替换掉整个recipientList,而不仅仅是recipientList调用的http目标 作为一种简单的方法,使用。要在处理器中编织,如下所示:
weaveByType(RecipientListDefinition.class).replace().process(...)
与adviceWith一样,请确保实现isUseAdviceWith以返回true,然后在对RoutedDefinition进行通知后调用context.start 我假设这是在一个扩展了CamelTestSupport的单元测试的上下文中,对吗?是的,Ray,你是对的。