我對嵌入式Camel路由中的遠程JMS隊列有一個持久的使用者。是否有可能通過主從配置進行這種路由?現在看起來,當啓動從屬ActiveMQ時,駱駝路由已經啓動並且已經激活,而不是實際的故障轉移發生時。只有當從站在故障轉移中變爲活動狀態時,如何在從站ActiveMQ上啓動駱駝路由?
現在,它會使從屬實例接收到也發送給主服務器的相同消息,並導致重複消息在故障轉移時到達隊列。
我正在使用ActiveMQ 5.3以及Apache Camel 2.1。
我對嵌入式Camel路由中的遠程JMS隊列有一個持久的使用者。是否有可能通過主從配置進行這種路由?現在看起來,當啓動從屬ActiveMQ時,駱駝路由已經啓動並且已經激活,而不是實際的故障轉移發生時。只有當從站在故障轉移中變爲活動狀態時,如何在從站ActiveMQ上啓動駱駝路由?
現在,它會使從屬實例接收到也發送給主服務器的相同消息,並導致重複消息在故障轉移時到達隊列。
我正在使用ActiveMQ 5.3以及Apache Camel 2.1。
這不應該是一個問題,因爲在從駱駝背景/路由將不啓動,直到它成爲主(當消息存儲文件鎖定由原型釋放)
不幸的是,當從經紀人開始,所以CamelContext以及路線。然而,你可以通過執行實現這一目標如下:
在部署從經紀人camelContext添加以下的自動啓動屬性,以防止啓動路線:
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring" autoStartup="false">
...
</camelContext>
接下來,你需要創建一個實現類ActiveMQ服務接口。這方面的一個示例是如下:
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;
}
}
然後在代理的配置文件,activemq.xml中,添加以下注冊服務:
<services>
<bean xmlns="http://www.springframework.org/schema/beans" class="com.fusesource.example.CamelContextService">
<property name="camel" ref="camel"/>
</bean>
</services>
現在,一旦從經紀人接任主,啓動方法將在服務類上被調用,並且路由將被啓動。
我也張貼了關於這個這裏博客:http://jason-sherman.blogspot.com/2012/04/activemq-how-to-startstop-camel-routes.html
駱駝routepolicies你可以決定根據自己的條件,暫停/恢復某些航線。 http://camel.apache.org/routepolicy.html
有一個現有的ZookeeperRoutePolicy可以用來做領導選舉。 http://camel.apache.org/zookeeper.html(見頁面底部)