ravi
ravi

Reputation: 1

Loading a Service on startup of the ServiceMix 4.3 which consumes another service using ActiveMQ/Apache Camel

We are trying with ServiceA calling ServiceB as soon as bundle loads during the SericeMix startup. Service2 having activemq endpoints we need to invoke a method of that particular service. I tried by spring init-method attribute in the bean tag which helps in auto trigger a method in ServiceA in that method I am calling the serviceB’s method. I am getting Exception like No Consumer available for the endpoint. I assume that as soon as the Service1 is up it is not getting the instance of the service2 which needs to get initialized using @Produce annotation activemq endpoint. The same services work fine in the other normal scenarios.

Exception: Caused by: org.apache.camel.CamelExchangeException: No consumers available on endpoint: Endpoint[direct://ServiceB]. Exchange[Message: BeanInvocation public java.lang.String java.lang.Object.toString() with null]] at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:46) at org.apache.camel.component.bean.CamelInvocationHandler.invoke(CamelInvocationHandler.java:64) ... 35 more

I am copy pasting the Code Block for your reference.

public class ServiceA{

    @Produce(uri = "direct:ServiceB") //Active MQ endpoint
    private ServiceB serviceB;

     public void start()
    {
        Object obj = serviceB.getData();    }
        . . . 
        .....   
    }
  }

     **bundle-context.xml**

        //Changes for method to auto trigger during spring bean load
        <bean id="serviceA" class="com.test.serviceA" init-method="start">
        </bean>

      **bundle-context-camel.xml**

         <osgi:camelContext id="ServiceA"
    xmlns="http://camel.apache.org/schema/spring">
    <template id="producerTemplate" />

    <!-- These routes are outbound to other services -->
    <route>
        <from uri="ServiceB" />
        <bean ref="enrichOutboundExchangeRef" />
        <to uri="activemq:ServiceB?transferException=true" />
    </route>
               ..............
    </osgi:camelContext>

Or is their anyother way if i need to achieve this requirement? where i can load a service(consumes other services) automatically during the servicemix bootup.

Upvotes: 0

Views: 1051

Answers (3)

Ben ODay
Ben ODay

Reputation: 21015

If you are getting "no consumers available on endpoint", it means that messages are being routed to an endpoint that hasn't been initialized. I recommend decoupling the services using a JMS queue between them. That way serviceA can put messages in the queue (independent of serviceB's availability) and serviceB can then act as a polling consumer against that queue whenever its ready.

Upvotes: 0

Ravi
Ravi

Reputation: 1

We tried the above approach but we still we are getting exceptions, we resolved it by adding a listener to the onCamelContextStarted() during th init of the serviceA.

Thanks Ravi

Upvotes: 0

Claus Ibsen
Claus Ibsen

Reputation: 55555

You can use seda instead of direct as it's queue based and thus consumers can come and go.

Also try using springs depends-on attribute

<bean id="serviceA" depends-on="myCamel" .../>

<osgi:camelContext id="myCamel" ...>

Upvotes: 1

Related Questions