如何在 AdviceWithRouteBuilder 中使用 replaceFromWith

How does replaceFromWith with in AdviceWithRouteBuilder

我在我的单元测试中使用了 AdviceWithRouteBuilder,但我不确定 replaceFromWith 方法是如何工作的。我正在测试的路线看起来像这样:

from(FTP_ENDPOINT)
    choice()
        when(predicateA)
            to("routeA")
        when(predicateB)
            to("routeB)
        otherwise()
            to("routeC");

from("routeA")
    to(SOMEWHERE)

from("routeB")
    to(SOMEWHER)

etc...

我的单元测试使用 AdviceWithRouteBuilder 将 FTP_ENDPOINT 替换为 "direct:start",如下所示:

context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
    @Override
    public void configure() throws Exception {
        replaceFromWith("direct:start);
    }
});

我的问题是,replaceFromWith 如何知道要替换哪个端点?我只想替换 FTP_ENDPOINT.

您有 3 条路线,例如代码中的 3 x from。在建议中,您 select 第一条路线,当您说 'get(0)' 时,例如

context.getRouteDefinitions().get(0)

因此它将使用第一条路线,您可以使用 get(1) 到 select 第二条路线。如果您为路线分配 ID,您还可以 select 按路线 ID。