Apache Camel:如何存储变量以备后用 [英] Apache Camel: how store variable for later use
问题描述
在使用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:
- 客户端将带有XML正文的HTTP POST消息发送到CAMEL
- CAMEL将HTTP POST消息代理到服务器,并使用 接收到的XML正文中获取信息(例如:使用XPATH过滤出某个参数)
- CAMEL收到答复后,CAMEL使用1中接收到的XML正文中的参数向服务器发送HTTP PUT消息.
- client sends HTTP POST message with XML body to CAMEL
- CAMEL proxies HTTP POST message towards server, with the URI slightly adapted using info from the received XML body (eg: use XPATH to filter out a certain parameter)
- after CAMEL has received a reply, CAMEL sends HTTP PUT message towards server, using parameters out of the XML body received in 1
所以像这样:
<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 :).
推荐答案
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屋!