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

查看:114
本文介绍了如何设置"Pick"?在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的骆驼类.我发现的东西声称,我允许您快速 刷新了一个能够以零Java代码执行最典型的聚合任务的AggregationStrategy."这对我来说很有用,因为我们希望尽可能多地使用XML进行配置.因此,避免编写将是一个很好的选择.我自己在Java中的AggregationStrategy.问题是,我不知道如何使用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从消息中选择要聚合的元素,并过滤出与Predicate 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的原因是在

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类的源代码.第十个结果是来自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以便我可以使用FlexibleAggregationStrategy吗?如果您知道其他任何信息,则需要对其进行配置,或者对其进行任何其他常见的陷阱,该信息也将不胜感激.

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流畅的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表达式转换富集路径中的结果主体,然后将其与

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>

希望有帮助.

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

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