【问题标题】:How to use Camel Message Filter Bean in Spring XML如何在 Spring XML 中使用 Camel 消息过滤器 Bean
【发布时间】:2014-03-12 19:59:57
【问题描述】:

Camel documentation for Message Filter 展示了几个使用“过滤器 bean”的 Java DSL 示例,如下所示:

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");
    }
}

但是该页面没有显示如何在 Spring XML 中调用该 bean:

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

在上面的 sn-p 中,我如何将我的&lt;filter/&gt; 与 Java bean 连接起来,该 Java bean 需要实现/扩展什么接口?

【问题讨论】:

    标签: java configuration filtering apache-camel imessagefilter


    【解决方案1】:

    你应该可以这样做:

    <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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-09-16
        • 2017-04-24
        • 2023-03-19
        • 2012-02-13
        • 1970-01-01
        • 2011-12-14
        • 2013-11-08
        • 1970-01-01
        相关资源
        最近更新 更多