主备份服务器的回复响应模式

时间:2013-09-09 11:49:37

标签: java spring spring-integration

备份服务器不断向主服务器发送keepAlive消息。主服务器回复消息'嘿,我还在运行。'。如果答复尚未到来,则备份服务器将接管并启动新的消息驱动适配器。

  1. 如何在Spring Integration中有效实现这一点?
  2. 如何从我的代码启动消息驱动的适配器,而不是由Spring ApplicationContext自动启动。
  3. 更新:这是我目前的做法:

    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)当答复未来时,有些人会调用服务(?)。

1 个答案:

答案 0 :(得分:1)

auto-startup设为false;您可以使用Lifecycle方法启动/停止适配器;您可以直接执行此操作(将其作为Lifecycle注入,或通过向<control=bus/>发送邮件(例如@keepAliveMessageAdapter.start()

您可以将状态保存在某个bean中(每次获得ping时),并配置<inbound-channel-adapter/>以轮询该bean上的方法,该方法返回控制总线命令以启动/停止适配器。