You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Marco Crivellaro <ma...@gmail.com> on 2013/02/19 11:45:51 UTC

camel shutsdown route even when using failover

Hi All,
I am setting up a camel context with 2 routes consuming 2 ActiveMQ queues.
The connectionstring to the broker specifies failover protocol, however if
the broker for some reason goes offline the context shutsdown itself
automatically. Is there a way to keep the context trying to reconnect to
ActiveMQ?

my spring context is as following:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
         http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
         http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">

  <camelContext id="hulkcontext"
xmlns="http://camel.apache.org/schema/spring" autoStartup="false">
    <package>com.crive</package>
    
    <route>
   		<from uri="jms:queue:crive.data"/>
   		<to uri="bean:myDataProcessor"/>
   		<inOut uri="mock:dataresult" />   		
	</route>
	<route>
   		<from uri="jms:queue:crive.status"/>
   		<to uri="bean:myStatusProcessor"/>
   		<inOnly uri="mock:statusresult" />
	</route>
    
    
  </camelContext>

  
  <bean id="myDataProcessor" class="com.crive.DataProcessor"/>
  <bean id="myStatusProcessor" class="com.crive.StatusProcessor"/>  

  
  <bean id="jms"
class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="connectionFactory">
      <bean class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL"
value="failover://(tcp://hostname:61616)?initialReconnectDelay=100"/>
      </bean>
    </property>
  </bean>
</beans>





main method is as following:

	public static void main(String[] args) throws Exception {
	
				
		ApplicationContext appContext = new
FileSystemXmlApplicationContext("camel-context.xml");
		final SpringCamelContext context = (SpringCamelContext)
appContext.getBean("hulkcontext");
		context.start();
		
		Runtime rt = Runtime.getRuntime();
		rt.addShutdownHook(new Thread() {
			public void run() {
				LOG.info("Application is being shutdown.");
				try {						
					context.stop();						
				} catch (Exception e) {
					LOG.error("Exception occured while stopping the service", e);
				}
			}
		});
		
		
	}






it looks like the shutdown hook is being called as in the Logs I can find
"Application is being shutdown." but I am not calling it programmatically



--
View this message in context: http://camel.465427.n5.nabble.com/camel-shutsdown-route-even-when-using-failover-tp5727781.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel shutsdown route even when using failover

Posted by Marco Crivellaro <ma...@gmail.com>.
I manage to get it working, I think I was setting the context in the wrong
way.
This now works, camel context won't stop and wait for the broker to
reconnect using failover provided via config


public class MainHulk {

	private static Logger LOG = LoggerFactory.getLogger(MainHulk.class);
	private Main main;
	
	
	public static void main(String[] args) throws Exception  {
	
		DOMConfigurator.configure("log4j.xml");
		LOG.info("Starting HULK mock");
		MainHulk hulk = new MainHulk();
		
		hulk.boot();
	}
	
	public void boot() throws Exception {
		main = new Main();
		main.setFileApplicationContextUri("camel-context.xml");
    	main.enableHangupSupport();
		main.run();
	}

}




--
View this message in context: http://camel.465427.n5.nabble.com/camel-shutsdown-route-even-when-using-failover-tp5727781p5727825.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel shutsdown route even when using failover

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Feb 19, 2013 at 3:17 PM, Marco Crivellaro <ma...@gmail.com> wrote:
> I've tried what you've suggested but the route will shutdown in in case the
> broker connection is lost, in my previous test it looked like System.Runtime
> was being called. This is how my main method looks like now:
>

Maybe its due the JVM terminating itself when there is no non-daemon
threads anymore.
Not sure if that's the case though.



>
> public class MainHulk {
>
>         private static Logger LOG = LoggerFactory.getLogger(MainHulk.class);
>         private Main main;
>         public static void main(String[] args) throws Exception  {
>
>                 LOG.info("Starting HULK mock");
>                 MainHulk hulk = new MainHulk();
>                 DOMConfigurator.configure("log4j.xml");
>                 hulk.boot();
>         }
>
>         public void boot() throws Exception {
>                 main = new Main();
>                 main.enableHangupSupport();
>                 main.setApplicationContext(new
> FileSystemXmlApplicationContext("camel-context.xml"));
>         }
>
> }
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-shutsdown-route-even-when-using-failover-tp5727781p5727795.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: camel shutsdown route even when using failover

Posted by Marco Crivellaro <ma...@gmail.com>.
I've tried what you've suggested but the route will shutdown in in case the
broker connection is lost, in my previous test it looked like System.Runtime
was being called. This is how my main method looks like now:


public class MainHulk {

	private static Logger LOG = LoggerFactory.getLogger(MainHulk.class);
	private Main main;
	public static void main(String[] args) throws Exception  {
	
		LOG.info("Starting HULK mock");
		MainHulk hulk = new MainHulk();
		DOMConfigurator.configure("log4j.xml");
		hulk.boot();
	}
	
	public void boot() throws Exception {
		main = new Main();
		main.enableHangupSupport();		
		main.setApplicationContext(new
FileSystemXmlApplicationContext("camel-context.xml"));
	}

}



--
View this message in context: http://camel.465427.n5.nabble.com/camel-shutsdown-route-even-when-using-failover-tp5727781p5727795.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel shutsdown route even when using failover

Posted by Marco Crivellaro <ma...@gmail.com>.
As long as the broker is only the application keeps running, it is only once
the broker is offline that the application is shut down. I will try your
suggestions and let you know.



--
View this message in context: http://camel.465427.n5.nabble.com/camel-shutsdown-route-even-when-using-failover-tp5727781p5727787.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel shutsdown route even when using failover

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

Are you sure your app keep running.
The start method on spring app context is non blocking.

See these FAQs
http://camel.apache.org/running-camel-standalone.html
http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html

On Tue, Feb 19, 2013 at 11:45 AM, Marco Crivellaro
<ma...@gmail.com> wrote:
> Hi All,
> I am setting up a camel context with 2 routes consuming 2 ActiveMQ queues.
> The connectionstring to the broker specifies failover protocol, however if
> the broker for some reason goes offline the context shutsdown itself
> automatically. Is there a way to keep the context trying to reconnect to
> ActiveMQ?
>
> my spring context is as following:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xsi:schemaLocation="
>          http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
>          http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-spring.xsd">
>
>   <camelContext id="hulkcontext"
> xmlns="http://camel.apache.org/schema/spring" autoStartup="false">
>     <package>com.crive</package>
>
>     <route>
>                 <from uri="jms:queue:crive.data"/>
>                 <to uri="bean:myDataProcessor"/>
>                 <inOut uri="mock:dataresult" />
>         </route>
>         <route>
>                 <from uri="jms:queue:crive.status"/>
>                 <to uri="bean:myStatusProcessor"/>
>                 <inOnly uri="mock:statusresult" />
>         </route>
>
>
>   </camelContext>
>
>
>   <bean id="myDataProcessor" class="com.crive.DataProcessor"/>
>   <bean id="myStatusProcessor" class="com.crive.StatusProcessor"/>
>
>
>   <bean id="jms"
> class="org.apache.activemq.camel.component.ActiveMQComponent">
>     <property name="connectionFactory">
>       <bean class="org.apache.activemq.ActiveMQConnectionFactory">
>         <property name="brokerURL"
> value="failover://(tcp://hostname:61616)?initialReconnectDelay=100"/>
>       </bean>
>     </property>
>   </bean>
> </beans>
>
>
>
>
>
> main method is as following:
>
>         public static void main(String[] args) throws Exception {
>
>
>                 ApplicationContext appContext = new
> FileSystemXmlApplicationContext("camel-context.xml");
>                 final SpringCamelContext context = (SpringCamelContext)
> appContext.getBean("hulkcontext");
>                 context.start();
>
>                 Runtime rt = Runtime.getRuntime();
>                 rt.addShutdownHook(new Thread() {
>                         public void run() {
>                                 LOG.info("Application is being shutdown.");
>                                 try {
>                                         context.stop();
>                                 } catch (Exception e) {
>                                         LOG.error("Exception occured while stopping the service", e);
>                                 }
>                         }
>                 });
>
>
>         }
>
>
>
>
>
>
> it looks like the shutdown hook is being called as in the Logs I can find
> "Application is being shutdown." but I am not calling it programmatically
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-shutsdown-route-even-when-using-failover-tp5727781.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen