【问题标题】:Apache Camel Rest - How to send request and response from previous endpoint to nextApache Camel Rest - 如何将请求和响应从上一个端点发送到下一个端点
【发布时间】:2019-11-22 15:50:33
【问题描述】:

我想实现一个骆驼 DSL 逻辑,例如,我有两个路由,其中​​收到的第一个路由的请求应该与来自第一个路由的响应一起传递到第二个路由。我如何做到这一点?

        `.to("direct:validatePayload")
            .to("bean:fundService?method=depositFund(${exchange})")
            .to("bean:rparticipantService?method=notifyParticipant(${exchange})");`

在上面的代码中,在验证请求负载后,具有 Fund 主体的交易所作为请求传递给 depositFund。在此之后,我想将请求传递给 notifyParticipant,这将结合来自 depositFund 的响应以及 depositFund 收到的请求。我如何通过骆驼 DSL 代码实现这一点。

【问题讨论】:

    标签: java rest spring-boot apache-camel


    【解决方案1】:

    查看消息历史记录:https://cwiki.apache.org/confluence/display/CAMEL/Message+History

    rparticipantService#notifyParticipant 中,您应该能够查找历史记录并获得fundService#depositFund 的结果。

    List<MessageHistory> list = exchange.getProperty(Exchange.MESSAGE_HISTORY, List.class);
    

    您还需要调整 MessageHistoryFactory 才能访问消息 + 正文:

    camelContext.getMessageHistoryFactory().setCopyMessage(true);
    

    【讨论】:

      猜你喜欢
      • 2021-06-06
      • 2021-12-14
      • 1970-01-01
      • 1970-01-01
      • 2020-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-25
      相关资源
      最近更新 更多