gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 11:28:57 24 4
gpt4 key购买 nike

备份服务器不断向主服务器发送 keepAlive 消息。主服务器回复消息“嘿,我还在运行。”。如果没有回复,备份服务器接管并启动一个新的消息驱动适配器。

  1. 如何在 Spring Integration 中高效地实现这一点?
  2. 如何从我的代码启动一个消息驱动的适配器,而不是由 Spring ApplicationContext 自动启动。

更新:这是我目前的做法:

发件人:

<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) 以某种方式在没有收到回复时调用服务 (?)。

最佳答案

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

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

关于java - 主备服务器的回复-响应模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18697573/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com