如何设置“选择"?Spring XML 中 Apache Camel 的 FlexibleAggregationStrategy 表达式? [英] How does one Set the "Pick" Expression for Apache Camel's FlexibleAggregationStrategy in Spring XML?

查看:14
本文介绍了如何设置“选择"?Spring XML 中 Apache Camel 的 FlexibleAggregationStrategy 表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Apache Camel 2.14 在 Spring XML 中配置 Apache Camel 路由.路由将涉及 <aggregator><enrich>/<pollEnrich>;我对 Camel 的经验还不够丰富,无法知道哪个 EIP 最有用.无论哪种方式,我都需要一个aggregationStrategy.我的最终目标是为希望在 XML 中配置路由的客户创建 Camel 路由.

I am attempting to configure an Apache Camel route in Spring XML using Apache Camel 2.14. The route will involve either an <aggregator> or an <enrich>/<pollEnrich>; I'm not yet experienced enough with Camel to know which EIP will be most useful. Either way, I'm going to need an aggregationStrategy. My end goal involves creating a Camel route for a client who wants the routes configured in XML.

通过在 Internet 上搜索,我了解到存在一个名为 FlexibleAggregationStrategy 的 Camel 类.我发现的东西声称,我引用,它可以让你快速用零 Java 代码创建一个能够执行最典型聚合任务的 AggregationStrategy."这对我来说听起来很有用,因为我们希望尽可能多地使用 XML 进行配置.因此,最好避免编写我自己的 AggregationStrategy 在 Java 中.问题是,我不知道如何使用 FlexibleAggregationStrategy.

By searching around the Internet, I learned of the existence of a Camel class called FlexibleAggregationStrategy. The things I found claim, and I quote, "It allows you to quickly whip up an AggregationStrategy that is capable of performing the most typical aggregation duties, with zero Java code." This sounds useful to me, since we want as much of the configuration in XML as possible. As such, it would be nice to avoid writing my own AggregationStrategy in Java. The problem is, I can't figure out how to use a FlexibleAggregationStrategy.

据我所知,FlexibleAggregationStrategy 使用名为 pickExpressionExpression 从消息中挑选元素进行聚合,并过滤掉匹配的消息谓词 conditionPredicate.所以,我假设我需要有一种方法在我的 Spring XML 中设置这些值.不幸的是,我无法让以下代码块工作:

From what I can tell, the FlexibleAggregationStrategy picks elements from messages to aggregate using an Expression called pickExpression, and filters out messages that match the Predicate conditionPredicate. So, I assume I need to have a way to set these values in my Spring XML. Unfortunately, I haven't been able to get the following blocks of code work:

属性名称设置为pickExpression,值作为元素:

Property name set to pickExpression, value as element:

<bean id="FlexibleAggregationStrategy"
    class="org.apache.camel.util.toolbox.FlexibleAggregationStrategy">
    <property name="pickExpression">
        <xpath>
            //ID
        </xpath>
    </property>
</bean>

属性名称设置为pick,值作为元素:

Property name set to pick, value as element:

<bean id="FlexibleAggregationStrategy"
    class="org.apache.camel.util.toolbox.FlexibleAggregationStrategy">
    <property name="pick">
        <xpath>
            //ID
        </xpath>
    </property>
</bean>

属性名称设置为pickExpression,值作为属性:

Property name set to pickExpression, value as attribute:

<bean id="FlexibleAggregationStrategy"
    class="org.apache.camel.util.toolbox.FlexibleAggregationStrategy">
    <property name="pickExpression" value="&lt;xpath&gt;//ID&lt;/xpath&gt;"/>
</bean>

属性名称设置为pick,值作为属性:

Property name set to pick, value as attribute:

<bean id="FlexibleAggregationStrategy"
    class="org.apache.camel.util.toolbox.FlexibleAggregationStrategy">
    <property name="pick" value="&lt;xpath&gt;//ID&lt;/xpath&gt;"/>
</bean>

每次,我都会收到一条错误消息,抱怨无法找到具有我给它的名称的属性描述符.我尝试 pickpickExpression 的原因是,在 这似乎是 FlexibleAggregationStrategy 的源代码,该变量包含类中的选择表达式被命名为pickExpression,但是设置它的方法被简单地称为pick().

Each time, I get an error complaining that it's unable to find the property descriptor with the name I give it. The reason I try both pick and pickExpression is that, in what appears to be the source code for FlexibleAggregationStrategy, the variable holding the pick expression in the class is named pickExpression, but the method to set it is simply called pick().

我对 Spring XML 没有完全的了解,但据我所知,使用 <property> 标记设置变量值需要 bean 具有 getter 和 setter那个变量.由于 FlexibleAggregationStrategy 没有用于 pickExpression 的 getter 和 setter,所以无论如何我都采用了错误的方法.但是,如果我正在阅读 <bean> 的 XML 模式定义; 标记 正确,向 bean 发送信息的唯一方法是使用 <property> 标记或构造函数参数.由于 FlexibleAggregationStrategy 没有设置 pickExpression 的构造函数,因此我还没有找到一种无需编写 Java 代码即可配置 FlexibleAggregationStrategy 的方法.

I don't have a perfect understanding of Spring XML, but based on what I know, using the <property> tag to set a variable value requires the bean to have getters and setters for that variable. Since FlexibleAggregationStrategy does not have getters and setters for pickExpression, I'm following the wrong approach anyway. However, if I'm reading the XML Schema Definition for the <bean> tag correctly, the only way to send information to a bean is with the <property> tag or with constructor parameters. Since FlexibleAggregationStrategy has no constructors that set pickExpression, I haven't found a way to configure a FlexibleAggregationStrategy without writing Java code.

我发现了对方法注入"的引用,它可能允许我配置 FlexibleAggregationStrategy.但是,我发现的唯一说明涉及用 Java 编写一个 bean.因此,这项技术还涉及编写 Java 代码;另外,似乎只写我自己的AggregationStrategy会更快更直接.

I've found references to something called "method injection" that might allow me to configure a FlexibleAggregationStrategy. However, the only instructions I've found involve writing a bean in Java. As such, this technique also involves writing Java code; in addition, it seems like it would be faster and more direct to just write my own AggregationStrategy.

截至目前,记录 <aggregator> 模式的新旧 Apache Camel Wiki 页面都根本没有提及 FlexibleAggregationStrategy.

As of now, neither the old nor new Apache Camel Wiki pages documenting the <aggregator> pattern does not mention FlexibleAggregationStrategy at all.

我尝试在 Google 上搜索术语 FlexibleAggregationStrategy 以查看是否有人编写了任何使用 FlexibleAggregationStrategy 的教程或文档.到目前为止,我得到的前两个 Google 结果是为 FlexibleAggregationStrategy 类自动生成的 Javadoc.第三个结果是我在上面链接的 github 托管的源代码.第四个结果是我发布的关于这个主题的另一个问题;这个问题已关闭,因为我不明白如何编写正确的 StackOverflow 问题.第五个结果是托管在 grepcode.com 上的源代码.第六个结果是我不理解的接口的 Javadoc.第七个结果是其他人在 grokbase.com 上提出的问题;这个问题没有答案.第八个结果是其他人在 qnalist.com 上提出的问题,也没有答案.第九个结果似乎来自一个涉及提交 FlexibleAggregationStrategy 类的源代码的邮件列表.第 10 个结果是 grokbase 发布到 osdir.com 的问题.类似的搜索返回大部分相同的结果;我发现的其他新结果同样无济于事.我认为,如果有人为使用 FlexibleAggregationStrategy 编写了一个很好的指南,它会出现在这些搜索中.

I have attempted a Google search for the term FlexibleAggregationStrategy to see if anybody has written any tutorials or documentation for using a FlexibleAggregationStrategy. As of now, the first two Google results I get are automatically-generated Javadoc for the FlexibleAggregationStrategy class. The third result is the github-hosted sourcecode I linked above. The fourth result is another question on this topic that I posted; this question was closed because I didn't understand how to write proper StackOverflow questions. The fifth result is the source code hosted on grepcode.com. The sixth result is the Javadoc for an interface I don't understand. The seventh result is a question somebody else asked on grokbase.com; the question has no answers. The eigth result is a question somebody else asked on qnalist.com that also has no answers. The ninth result seems to be from a mailing list involving committing the source code for the FlexibleAggregationStrategy class. The tenth result is the question from grokbase posted to osdir.com. Similar searches return mostly the same results; the other new results I find are equally unhelpful. I think that, if somebody had written a good guide for using FlexibleAggregationStrategy, it would come up in those searches.

有没有使用过 FlexibleAggregationStrategy 的人可以告诉我如何设置 pickExpressionconditionPredicate 以便我可以使用 灵活聚合策略?如果您知道我需要配置它的任何其他内容,或者任何其他围绕它的常见陷阱,那么这些信息也将不胜感激.

Is there anybody who has used a FlexibleAggregationStrategy who can tell me how to set the pickExpression and conditionPredicate so I can use a FlexibleAggregationStrategy? If you know of anything else I would need to configure it, or any other common pitfalls surrounding it, that information would also be appreciated.

感谢您的宝贵时间.

推荐答案

查看 javadoc 我会说这个类对 Camel XML-DSL 不友好,旨在与 Camel fluent Java-DSL 一起使用.如果您想将它与 Spring-DSL 一起使用,那么您就不走运了.

Looking at the javadoc I'd say this class is not Camel XML-DSL-friendly and intended to be used with the Camel fluent Java-DSL. You're out of luck if you want to use it with Spring-DSL.

您的用例可能更容易实现,方法是使用您的 xpath 表达式转换丰富路由中的结果主体,然后将其与 UseLatestAggregationStrategy 本质上使浓缩交换成为聚合的结果:

Your use case can probably be easier implemented by transforming the result body in the enrichment route using your xpath expression and then aggregate it with UseLatestAggregationStrategy which essentially makes the enrichment exchange the result of the aggregation:

<bean id="useLatest" class="org.apache.camel.processor.aggregate.UseLatestAggregationStrategy"/>

<camel:route id="main">
    ...
    <camel:enrich uri="direct:enrich" strategyRef="useLatest"/>
    ...
</camel:route>

<camel:route id="enrichment">
    <camel:from uri="direct:enrich"/>

    ...enrichment processing here...

    <camel:setBody>
        <camel:xpath>//ID</camel:xpath>
    </camel:setBody>
</camel:route>

希望对您有所帮助.

这篇关于如何设置“选择"?Spring XML 中 Apache Camel 的 FlexibleAggregationStrategy 表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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