apache-camel - 如何在 apache camel 中全局设置交换属性

例如:

from("direct:test")
  .multicast() 
     .to("direct:req1","direct:req2");

from("direct:req1")
  .to(cxf:bean:endpoint1)
  .process("response1");

from("direct:req2")
 .process("requestProcessor2")
 .to(cxf:bean:endpoint2)
 .process(response2);

我是 apache camel 的新手,我只是想知道有什么方法可以使用我从“requestProcessor2”中的端点 1 获得的响应。

最佳答案

你可以这样做

    from("direct:test")
            .setProperty("test.body", body())
            .to(cxf:bean:endpoint1)
            .setProperty("endpoint1.body", body())
            .process("response1")
            .setBody(exchangeProperty("test.body"))
            .to("direct:req2")

    from("direct:req2")
            .process("requestProcessor2")
            .to(cxf:bean:endpoint2)
            .process(response2);

您将原始主体保存在一个属性中,还保存了端点 1 中的主体。然后,您将交换发送到 direct:req2,原始正文在 exhcnage 正文中,正文在您可以访问的属性中形成 endpoint1(在您的处理器中或其他地方)。

访问处理器中的属性:

public void process(final Exchange exchange) throws Exception {

    Object body = exchange.getProperty("endpoint1.body");

}

https://stackoverflow.com/questions/38410908/

相关文章:

types - Julia 中的大宽度整数?

regex - 如何在 Chrome Dev Tools 中过滤没有扩展的 XHR 请求?

git - 是否可以轻松地将所有提交从一个分支移动到另一个分支作为一个提交?

php - woocommerce rest API 每次调用仅提供 10 个订单

assembly - 汇编中的函数结语

r - 如何在 R 中绘制阶乘函数

git - 无法解析主机名

types - 结构的透析器错误

xamarin.forms - 从 Xamarin 的 Picker 中获取选定的值

google-apps-script - 可以在谷歌脚本中设置一个标题