【问题标题】:Loop with apache camel用 apache 骆驼循环
【发布时间】:2013-10-17 01:28:51
【问题描述】:

我希望在一个请求中执行多项操作。我需要循环 xml 以使用 Apache 骆驼路由执行以下操作。 1)获取请求xml中的总操作并放入变量中。 2) 在 xml 上使用 xpath 获取表达式的总数并放入列表 3) 循环(操作总数)次以评估表达式

第一步是列出 nodeList = /tractscation/operations

<loop>
<constant>nodeLIst.length</xpath>
compare and execute operation
</loop>

以上行只是伪代码,我希望任何人帮助我使用骆驼 Xpath 和循环的确切代码。 .

我是 xpath 和骆驼的新手。我们正在使用 camelxpath spring DSL

【问题讨论】:

标签: xpath xml-parsing apache-camel


【解决方案1】:

如果你想遍历每个与 xpath 匹配的节点并单独处理它,那么使用camel-splitter EIP...

<route>
    <from uri="direct:a"/>
    <split>
        <xpath>/transaction/operations</xpath>
        <to uri="direct:b"/>
    </split>
</route>

否则,有一个camel-loop EIP 可用于执行同一进程可变次数...但拆分器通常用于解析/循环类型的操作

from("direct:c").loop().xpath("/hello/@times").to("mock:result");

【讨论】:

  • 非常感谢。我需要处理每个节点并将它们路由到不同的处理器。通过处理节点类型并相应地将它们中的每一个路由到不同的目的地,类似于动态路由。您能否告诉我我可以编写的任何小型架构的想法以实现无缝集成
  • 我曾经像 一样使用 xpath 来遍历 bean 。现在我想结合这两个 bean 的响应,我必须使用聚合器 ..anybdy plz 可以帮助解决这个问题。
【解决方案2】:

希望对你有帮助=D

内部路线

    <to uri="direct:WSCall" />

    <split strategyRef="groupExchangeAggregationStrategy">
          <xpath>//response/operation</xpath>
    </split>

速度模板

<tag>
   #foreach( $exchangeItem in ${body} )
      ${exchangeItem.in.body}
   #end
</tag>

包括

<beans>
  <bean id="groupExchangeAggregationStrategy" class="org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy" />
</beans>

【讨论】:

    猜你喜欢
    • 2022-01-06
    • 2019-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-05
    • 2016-12-08
    • 2022-01-19
    • 1970-01-01
    相关资源
    最近更新 更多