【问题标题】:Multiple Camel Proxys in same camel context同一骆驼上下文中的多个骆驼代理
【发布时间】:2014-10-27 08:43:34
【问题描述】:

我正在尝试使用骆驼代理和 Java 接口调用直接端点。我将此接口作为 OSGI 服务公开给另一个包并访问该包中的接口。一切正常,现在我需要使用相同的接口在相同的骆驼上下文中基于某些条件调用另一个直接端点。我该怎么做?

    Camel routes:
    <camelContext id="cContext" trace="false" xmlns="http://camel.apache.org/schema/blueprint">

    <proxy id="camelProxyService"
               serviceInterface="com.xxx.CamelProxyService"
               serviceUrl="direct:endpoint1" />

    <route id="route1">
       <from uri="direct:endpoint1" />
       <to uri="seda:a" />
    </route>

    <route id="route2">
      <from uri="direct:endpoint2" />
       <to uri="seda:b" />
    </route>
    </camelContext>

    <service ref="camelProxyService" interface="com.xxx.CamelProxyService"/>


    public interface CamelProxyService {

        public void method1(String str);

        public void method2(String str);
    }

    How can i define the interface as camel proxy in camel context and mention method names to call different direct endpoints? Any help is appreciated.

【问题讨论】:

    标签: apache-camel jbossfuse blueprint-osgi apache-servicemix


    【解决方案1】:
    <proxy id="camelProxyService"
               serviceInterface="com.uday.camel.proxy.CamelProxyService"
               serviceUrl="direct:endpoint1" />
    <camel:route>
        <camel:from uri="direct:endpoint1"/>
        <camel:process ref="conditionProcess"/>
        <camel:choice>
            <camel:when>
                <camel:header>${condition}=method1</camel:header>
                <camel:to uri="seda:a"/>
            </camel:when>
            <camel:otherwise>
                <camel:to uri="seda:b"/>
            </camel:otherwise>
        </camel:choice>
        <camel:stop/>
    </camel:route>
    

    公共类 ConditionProcess 实现处理器 {

    @Override
    public void process(Exchange exchange) throws Exception {
        BeanInvocation invocation = exchange.getIn().getBody(BeanInvocation.class);
        String methodName = invocation.getMethod().getName();
        exchange.getIn().setHeader("condition", methodName);
        System.out.println("Method "+methodName);
    }
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 2021-08-13
      • 2014-02-11
      • 2015-06-30
      • 2022-01-11
      • 1970-01-01
      • 2015-05-31
      相关资源
      最近更新 更多