Apache Camel:如何存储变量以供以后使用 [英] Apache Camel: how store variable for later use

查看:30
本文介绍了Apache Camel:如何存储变量以供以后使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 Spring DSL 与 Camel 玩耍"时,我遇到了以下问题.假设预期的消息流如下所示:

while 'playing around' with Camel using Spring DSL, I came across the following problem. Suppose the expected message flow looks like this:

  1. 客户端向 CAMEL 发送带有 XML 正文的 HTTP POST 消息
  2. CAMEL 将 HTTP POST 消息代理到服务器,URI 稍作修改,使用接收到的 XML 正文中的信息(例如:使用 XPATH 过滤掉某个参数)
  3. 在 CAMEL 收到回复后,CAMEL 使用 1 中收到的 XML 正文中的参数向服务器发送 HTTP PUT 消息

比如:

<route>
   <from uri="...">
   <to uri="...">
   <to uri="...">
 </route>

问题:如何在步骤 1 中将参数存储在 Spring DSL 中,以便稍后在步骤 3 中使用?

Question: how do I store the parameters in Spring DSL in step 1, so that I can use them later in step 3 ?

所以,我想从步骤 1 中接收到的消息的 XML 正文中提取 XML 参数,并将它们放入变量中,然后我可以使用这些变量来编写要在步骤 3 中发送的消息.

So, I would like to extract XML parameters out of the XML body of the message received in step 1 and put them into variables, which I then later on can use to compose the message to be sent in step 3.

为了提取参数,我正在考虑使用 XPATH.看起来不错,但我只是不知道如何将 XPATH 的输出放入变量中,然后稍后使用该变量......(语法??)

For extracting the parameters, I was thinking of using XPATH. That looks ok, but I just don't see how to put the output of the XPATH into a variable and then use that variable later on ... (syntax ??)

注意:如您所见,我的开发知识相当有限……抱歉.但是,如果有人可以帮助解决这个问题,那就太好了:).

Note: as you can see, my development knowledge is rather limited ... sorry for that. But it would still be great if someone could help with this :).

推荐答案

可以在Exchange 属性或像这样的消息头...

you can set store data in the Exchange properties or message headers like this...

.setHeader("ID", XPathBuilder.xpath("/order/@id", String.class))
.setProperty("ID", XPathBuilder.xpath("/order/@id", String.class))

然后像这样在 Exchange 的 bean/处理器中检索它们...

and then retrieve them in a bean/processor from the Exchange like this...

String propId = (String) exchange.getProperty("ID");
String headerId = (String) exchange.getIn().getHeader("ID");                        }

这篇关于Apache Camel:如何存储变量以供以后使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆