How to ensure Camel ProducerTemplate waits for CamelContext to start

I'm trying to use the @EndpointInject annotation to create a ProducerTemplate to connect my POJO to the CamelContext (as described here http://camel.apache.org/pojo-producing.html ).

The problem I'm running into is that the ProducerTemplate is injected into my POJO before all routes are fired in the camel context. So when I call createTemplate.send (...) I get an error DirectConsumerNotAvailableException: No consumers available on endpoint...

.

Is there something I need to do to ensure the CamelContext is started before trying to send the route?

+3


source to share


2 answers


You can use it block=true

as an option on a direct endpoint and it will wait for the consumer to be up and running. This should help.



Otherwise, you will need to write the code yourself to wait until CamelContext

it is launched. You can access it from the input ProducerTemplate

that has getCamelContext

.

Another alternative is to provide a dependency injection infrastructure if possible, set up your bean after Camel. If you are using spring xml then it has an attribute depends-on

that you can set in tags <bean>

.

+3


source


I do not understand your answer, Klaus Ibsen, the question is that of a producer, not a consumer. My suggestion to use a spring event



@EventListener(ApplicationReadyEvent.class)
public void onApplicationEvent() {
    producerTemplate.sendBody("demo");

}

      

0


source







All Articles