You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Josh Forman-Gornall <jo...@gmail.com> on 2014/05/21 10:24:17 UTC

Strange behaviour with spring + camel

Hi all,

I am seeing some strange behaviour with a very basic spring/camel
application... can anyone help me understand this?:

I have defined a spring bean for camelContext with one route (with
autoStartup="true") and when the bean is created, a thread will be created
which listens for incoming messages...

In my static void main method, I am simply initialising the application
context:
new ClassPathXmlApplicationContext("application-context.xml");

If I do this, the camelContext initialises successfully but then the
application terminates immediately.  However, if I add a Thread.sleep(2000)
after initialising the application-context,  then the application never
terminates (because there is a thread listening for incoming messages)....
this is what I expected to happen - but why do I need to have a
Thread.sleep ?

Thanks for any help,
Josh

Re: Strange behaviour with spring + camel

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

This is not strange, see
http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html

eg you need to keep the jvm running as creating a spring app context
is not a blocking call when you call its start method etc.


On Wed, May 21, 2014 at 10:24 AM, Josh Forman-Gornall
<jo...@gmail.com> wrote:
> Hi all,
>
> I am seeing some strange behaviour with a very basic spring/camel
> application... can anyone help me understand this?:
>
> I have defined a spring bean for camelContext with one route (with
> autoStartup="true") and when the bean is created, a thread will be created
> which listens for incoming messages...
>
> In my static void main method, I am simply initialising the application
> context:
> new ClassPathXmlApplicationContext("application-context.xml");
>
> If I do this, the camelContext initialises successfully but then the
> application terminates immediately.  However, if I add a Thread.sleep(2000)
> after initialising the application-context,  then the application never
> terminates (because there is a thread listening for incoming messages)....
> this is what I expected to happen - but why do I need to have a
> Thread.sleep ?
>
> Thanks for any help,
> Josh



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/