Purtroppo, quando lo schiavo il broker inizia così anche CamelContext insieme ai percorsi. Tuttavia è possibile raggiungere questo obiettivo nel modo seguente:
Sul camelContext schierato con mediatore di schiavo aggiungere il seguente L'avvio automatico attributo per evitare che i percorsi di avviarsi:
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring" autoStartup="false">
...
</camelContext>
successivo è necessario creare una classe che implementa il Interfaccia di servizio ActiveMQ. Un esempio di questo potrebbe essere il seguente:
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;
}
}
Poi, nel file di configurazione del broker, activemq.xml, aggiungere il seguente per registrare il servizio:
<services>
<bean xmlns="http://www.springframework.org/schema/beans" class="com.fusesource.example.CamelContextService">
<property name="camel" ref="camel"/>
</bean>
</services>
Ora, una volta che il broker schiavo prende il sopravvento come il master, il metodo start verrà invocato sulla classe di servizio e verranno avviati i percorsi.
ho anche inviato un blog su questo qui: http://jason-sherman.blogspot.com/2012/04/activemq-how-to-startstop-camel-routes.html
fonte
2012-04-30 21:59:31