备份服务器不断向主服务器发送keepAlive消息。主服务器回复消息'嘿,我还在运行。'。如果答复尚未到来,则备份服务器将接管并启动新的消息驱动适配器。
更新:这是我目前的做法:
SENDER:
<si:inbound-channel-adapter id="keepAlivePoller" channel="keepAliveChannel" method="sendMessage" >
<bean class="com.keepAlive.KeepAliveSender"/>
<si:poller fixed-rate="${keepalive.sendinterval}" max-messages-per-poll="1"></si:poller>
</si:inbound-channel-adapter>
这是我的接收者:
<si:channel id="pollKeepChannel">
<si:queue/>
</si:channel>
<int-jms:message-driven-channel-adapter id="keepAliveMessageAdapter"
channel="pollKeepChannel" destination="keepAlive" connection-factory="connectionFactory"
max-concurrent-consumers="2" auto-startup="true" acknowledge="transacted" extract-payload="true"/>
<si:service-activator id="keepAliveServiceActivator" input-channel="pollKeepChannel" ref="keepAliveService" method="process">
<int:poller />
</si:service-activator>
<bean id="keepAliveService" class="com.keepAlive.KeepAliveService"/>
<bean id="keepAlive"
class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="PREM_KEEPALIVE" />
</bean>
我想1)以某种方式接收来自发送服务器的回复。 2)当答复未来时,有些人会调用服务(?)。
答案 0 :(得分:1)
将auto-startup
设为false;您可以使用Lifecycle
方法启动/停止适配器;您可以直接执行此操作(将其作为Lifecycle
注入,或通过向<control=bus/>
发送邮件(例如@keepAliveMessageAdapter.start()
。
您可以将状态保存在某个bean中(每次获得ping时),并配置<inbound-channel-adapter/>
以轮询该bean上的方法,该方法返回控制总线命令以启动/停止适配器。