2014-09-03 3 views
0

J'essaye d'invoquer un point d'extrémité direct en utilisant un proxy camel et une interface Java. J'ai exposé cette interface en tant que service OSGI à un autre groupe et en accédant à l'interface de ce groupe. Tout a bien fonctionné et maintenant j'ai eu besoin d'invoquer un autre point de terminaison direct basé sur certaines conditions dans le même contexte de camel en utilisant la même interface. Comment puis-je faire ceci?Plusieurs Proxys Camel dans le même contexte camel

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. 

Répondre

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 public class implémente Processeur {

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

}