如何模拟动态 (toD) 端点

Chr*_*ris 4 apache-camel

大家好,

假设我必须遵循生产代码:

from("file:/home/test/from/")
  .setHeader("targetDynamicEndpoint", constant("file:/home/test/to/"))
  .toD("${header.targetDynamicEndpoint}")
Run Code Online (Sandbox Code Playgroud)

我如何能够模拟生产者端点(“toD”)?

我能够猜测传递给“toD”的字符串,因为它是通过 StringBoot 属性设置的

Aku*_*our 5

在测试中,您可以使用AdviceWith并调用 weaveByType 方法

例如:

camelContext.getRouteDefinition("routeId").adviceWith(camelContext, new AdviceWithRouteBuilder() {
        @Override
        public void configure() {
            weaveByType(ToDynamicDefinition.class).replace().to("mock:someMock")
        }
    });

MockEndpoint someMockEndpoint = camelContext.getEndpoint("mock:someMock", MockEndpoint.class);
Run Code Online (Sandbox Code Playgroud)

或者你甚至可以给生产者端点一个 id 并使用 weaveById 方法

  • 当路线中有多个 toD 时,您如何编织,是否可以以某种方式进行过滤? (3认同)