How to use Camel Message Filter Bean in Spring XML

倾然丶 夕夏残阳落幕 提交于 2019-12-11 19:35:34

问题


The Camel documentation for Message Filter shows several Java DSL examples using a "filter bean" like so:

from("direct:start")
    .filter().method(MyBean.class, "isGoldCustomer").to("mock:result").end()
    .to("mock:end");

public static class MyBean {
    public boolean isGoldCustomer(@Header("level") String level) {
        return level.equals("gold");
    }
}

But that page doesn't show how to invoke that bean in Spring XML:

<route id="my-route">
    <from uri="direct:a" />
    <filter>
        <method>??? how to call MyBean#isGoldCustomer from here???</method>
        <to uri="direct:b" />
    </filter>
</route>

In the above snippet, how do I wire my <filter/> with a Java bean, and what interface does that Java bean need to implement/extend?


回答1:


You should be able to do it like this:

<bean id="myCustomPredicate" class="com.hveiga.test.MyCustomPredicate"/> 

<route id="my-route">
    <from uri="direct:a" />
    <filter>
        <method ref="myCustomPredicate" />
        <to uri="direct:b" />
    </filter>
</route>



回答2:


<bean id="myCustomPredicate" class="com.hveiga.test.MyCustomPredicate"/>
<route id="my-route">
    <from uri="direct:a" />
    <filter>
        <method ref="myCustomPredicate" method="myCustomPredicateMethod"/>
        <to uri="direct:b" />
    </filter>
</route>


来源:https://stackoverflow.com/questions/21762743/how-to-use-camel-message-filter-bean-in-spring-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!