【问题标题】:Apache camel pass headers in recipient list收件人列表中的 Apache 骆驼通行证标头
【发布时间】:2021-01-30 09:04:22
【问题描述】:

我设置了以下路线,并为路线定义了两个处理器。

from(direct: a)
    .streamCaching()
    .process(new MyProcessorA())
    .toD(endpoint)
    .to("log:DEBUG?showBody=true&showHeaders=true")
    .log("Response from microservice: ${body}")
    .process(new MyProcessorB())
    .end()

我定义了一个 REST API 来调用带有收件人列表的路由,如下所示:

rest()
    .post("/accumulate")
    .route()
    .process(new RequestProcessor())
    .recipientList()
    .exchangeProperty(routes)
    .endRest();

我的收件人列表将定义一个路由列表,例如routeArouteB。我想通过从routeA 中提取响应字段来设置标题并在routeB 中使用它。我尝试在我的MyProcessorB 类中执行此操作,如下所示:

@Component
public class MyProcessorB implements Processor {

    @Override
    public void process(Exchange exchange) throws Exception {
        exchange.setHeader("accId", "acc1234");
    }
}

现在,当收件人列表执行routeB 时,我正在访问MyProcessorA 类中设置的标头,但我将它作为null 获取。我已经设置了一个调试点,并且已经看到 MyProcessorB 被调用并设置了标头,但是为什么我在下一个路由中会错过它呢?

【问题讨论】:

    标签: java apache-camel dsl spring-camel


    【解决方案1】:

    你应该看看routingSlip EIP。 recipientList 重复消息,routingSlip 在路由上按顺序迭代。 https://camel.apache.org/components/latest/eips/routingSlip-eip.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多