How to inject multiple endpoint in SEI using Camel's @EndpointInject

By default you can inject annotation on single method of an interface like:

public interface MyListener {

  @EndpointInject(uri="activemq:foo.bar")

    String sayHello(String name);

}

what if you need multiple methods like this with @EndpointInjection happening over them for each endpoint e.g.:

public interface MyListener {

  @EndpointInject(uri="direct:foo")

    String sayHelloFoo(String name);

@EndpointInject(uri="direct:bar")

    String sayHelloBar(String name);

}

The simple solution i have working involved spring's FactoryBean implementation.

It need following steps:

<!-- Define route for which you need injection to happen -->

<bean id="r" class="MyListener" />

<!-- Define producer template having that route  -->  

<camelContext  xmlns="http://camel.apache.org/schema/spring">

        <template id="producerTemplate" />

        <routeBuilder ref="r"/>

    </camelContext>

 <!-- define FactoryBean for proxy instance --> 

<bean id="definedCamel" class="CamelFactoryBean">

        <constructor-arg index="0" value="MyListener" />

        <constructor-arg index="1" ref="producerTemplate" />

</bean>

The FactoryBean will create instance of custom InvocationHandler and return it which will invoke the endpoint on the ProducerTemplate instance.



Comments

Popular posts from this blog

java.net.SocketException: Connection reset

Hide empty last column from Table/Tree Viewer

Spring: implements interface not working in @Controller