Camel advice在更改编织语句的顺序时表现不同

hel*_*hod 12 apache-camel

我有以下路线用于演示目的

from("direct:external")
    .routeId("external")
    .to("http4://www.third-party.com/foo").id("ext");
Run Code Online (Sandbox Code Playgroud)

为了测试,我想*用直接替换http4:端点:端点*在路由末尾添加一个mock:端点进行验证

我添加了以下adviceWithRouteBuilder

context.getRouteDefinition("external").adviceWith(context, new AdviceWithRouteBuilder() {
    @Override
    public void configure() throws Exception {
        weaveAddLast().to("mock:result");
        weaveByToUri(".*http4://.*")
            .replace()
            .to("direct:foo");
    }
});
Run Code Online (Sandbox Code Playgroud)

这个似乎工作,但如果我改变weave*语句的顺序,就像这样

public void configure() throws Exception {
    weaveByToUri(".*http4://.*")
        .replace()
        .to("direct:foo");
    weaveAddLast().to("mock:result");
}
Run Code Online (Sandbox Code Playgroud)

它给了我以下错误

java.lang.IllegalArgumentException:在路由中没有匹配:*的输出:Route(external)[[From [direct:external]] - > [pipeline - > [[To [direct:foo]]]]]

我实际上希望得到相同的结果,与订单无关.

Kha*_*led 7

这里需要注意的一点是,weave*调用只能识别原始的RouteBuilder.因此,当您weaveByUri()首先执行呼叫时,它将替换.to("http4://www.third-party.com/foo").to("direct:foo"),这恰好是您路由中的最后一个端点.现在,当您执行weaveAddLast()调用时,它会查找"http4://www.third-party.com/foo"但找不到它,因为它被替换为"direct:foo".这导致抛出异常.

因此,如果假设在端点之后还有另一个端点"http4...",那么它不再是您路由中的最后一个端点,那么您adviceWith()应该工作.例如,如果您的原始路线看起来像这样,它将起作用:

from("direct://external")
  .routeId("external")
  .to("http4://www.third-party.com/foo")
  .id("ext")
  .to("direct://bar")
;
Run Code Online (Sandbox Code Playgroud)

我应该注意到,我认为这是一个错误,订单无关紧要.

  • 谢谢,我记录了一张票,看看我们是否可以改进/解决这个问题:https://issues.apache.org/jira/browse/CAMEL-10855 (2认同)