Apache Camel Rest-如何从上一个端点向下一个端点发送请求和响应

时间:2019-11-22 15:50:33

标签: java rest spring-boot apache-camel

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

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

在上面的代码中,在验证了请求有效负载之后,将具有基金主体的交易所作为请求传递给depositFund。之后,我想将请求传递给notifyParticipant,这将是depositFund的响应与depositFund收到的请求的组合。如何通过骆驼DSL代码实现这一目标。

1 个答案:

答案 0 :(得分:0)

看看消息历史记录: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);