camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Camel + Spring + Spring Boot, waiting for the routes to start
Date Tue, 11 Apr 2017 13:34:30 GMT
Dont use the event listener to do code that may block
@EventListener(ContextRefreshedEvent.class)

You are basically hi-jacking the spring thread that signals this
event. You can create a new thread to send the message from the event
listener so you dont block it.




On Tue, Apr 11, 2017 at 1:30 PM, Artur Jablonski
<ajablonski@ravenpack.com> wrote:
> Hello,
>
> I have the Camel + Spring + SpringBoot combo working
>
>
> I have my RouteBilder Spring Component that's being pickup up and started
> during Spring startup.
> The route starts fine as I can see SpringCamelContext output in the logs.
>
> What I am trying to do is to send a message to direct endpoint using
> injected ProducerTemplate but if I do it like this
>
> @Produce(uri = "direct:myQueue")
> private ProducerTemplate producerTemplate;
>
> @EventListener(ContextRefreshedEvent.class)
> public void send()
>     throws Exception
> {
>     producerTemplate.start();
>     producerTemplate.sendBody("hello");
> }
>
>
> I am getting
>
>  No consumers available on endpoint: direct://myQueue
>
> because the route has not started yet and if I try blocking parameter on
> uri like this:
>
> @Produce(uri = "direct:myQueue?block=true")
>
> then the whole thing freezes for 30 secs (default timeout) and then blows
> up with the same exception
>
> I also tried to call the producerTemplate.sendBody() form @PostConstruct
> annotaded method with the same effect.
>
>
> How do I wait for the CamelContext to be fully started in this context????
>
>
> Cheerio
> Arur



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Mime
View raw message