Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Unfortunately, when the slave broker starts so does the CamelContext along with the routes. However you can accomplish this by doing the following:</p> <p>On the camelContext deployed with slave broker add the following autoStartup attribute to prevent the routes from starting:</p> <pre><code>&lt;camelContext id="camel" xmlns="http://camel.apache.org/schema/spring" autoStartup="false"&gt; ... &lt;/camelContext&gt; </code></pre> <p>Next you need to create a class that implements the ActiveMQ Service Interface. A sample of this would be as follows:</p> <pre><code>package com.fusesource.example; import org.apache.activemq.Service; import org.apache.camel.spring.SpringCamelContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Example used to start and stop the camel context using the ActiveMQ Service interface * */ public class CamelContextService implements Service { private final Logger LOG = LoggerFactory.getLogger(CamelContextService.class); SpringCamelContext camel; @Override public void start() throws Exception { try { camel.start(); } catch (Exception e) { LOG.error("Unable to start camel context: " + camel); e.printStackTrace(); } } @Override public void stop() throws Exception { try { camel.stop(); } catch (Exception e) { LOG.error("Unable to stop camel context: " + camel); e.printStackTrace(); } } public SpringCamelContext getCamel() { return camel; } public void setCamel(SpringCamelContext camel) { this.camel = camel; } } </code></pre> <p>Then in broker's configuration file, activemq.xml, add the following to register the service:</p> <pre><code>&lt;services&gt; &lt;bean xmlns="http://www.springframework.org/schema/beans" class="com.fusesource.example.CamelContextService"&gt; &lt;property name="camel" ref="camel"/&gt; &lt;/bean&gt; &lt;/services&gt; </code></pre> <p>Now, once the slave broker takes over as the master, the start method will be invoked on the service class and the routes will be started.</p> <p>I have also posted a blog about this here: <a href="http://jason-sherman.blogspot.com/2012/04/activemq-how-to-startstop-camel-routes.html" rel="nofollow">http://jason-sherman.blogspot.com/2012/04/activemq-how-to-startstop-camel-routes.html</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload