试图停止消息驱动的通道适配器但丢弃消息
Trying to stop a message-driven-channel-adapter but droppping a message
我正在尝试使用 SmartLifecycle
stop
方法停止 message-driven-channel-adapter
,但可能有 1/3 的时间会导致警告消息:
DefaultMessageListenerContainer - Rejecting received message because of the listener container having been stopped in the meantime
检查 ActiveMQ 表明消息确实丢失了。
我正在使用 JmsTemplate
让 ActiveMQ 与 Spring 集成通信。我的豆子看起来像:
<bean id="Topic" class="org.apache.activemq.command.ActiveMQQueue">...</bean>
<bean id="archiveTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="defaultDestination" ref="Topic"></property>
...
</bean>
<si:channel id="InputChannel" />
<jms:message-driven-channel-adapter
id="archiveInboundAdapter" channel="InputChannel" destination="Topic" />
<si:service-activator id="archiveConsumerActivator"
input-channel="InputChannel" ref="consumer" method="onMessage" />
然后在我的代码中,我获取 archiveInboundAdapter
bean 并对其调用 stop()
。
有什么想法吗?有没有更好的方法来停止接收消息?实际上,我试图以有序的方式处理系统关闭(停止接收消息,停止处理这些消息的复杂线程系统,退出)。
设置 acknowledge="transacted"
以便处理中的消息回滚到队列中。
我正在尝试使用 SmartLifecycle
stop
方法停止 message-driven-channel-adapter
,但可能有 1/3 的时间会导致警告消息:
DefaultMessageListenerContainer - Rejecting received message because of the listener container having been stopped in the meantime
检查 ActiveMQ 表明消息确实丢失了。
我正在使用 JmsTemplate
让 ActiveMQ 与 Spring 集成通信。我的豆子看起来像:
<bean id="Topic" class="org.apache.activemq.command.ActiveMQQueue">...</bean>
<bean id="archiveTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="defaultDestination" ref="Topic"></property>
...
</bean>
<si:channel id="InputChannel" />
<jms:message-driven-channel-adapter
id="archiveInboundAdapter" channel="InputChannel" destination="Topic" />
<si:service-activator id="archiveConsumerActivator"
input-channel="InputChannel" ref="consumer" method="onMessage" />
然后在我的代码中,我获取 archiveInboundAdapter
bean 并对其调用 stop()
。
有什么想法吗?有没有更好的方法来停止接收消息?实际上,我试图以有序的方式处理系统关闭(停止接收消息,停止处理这些消息的复杂线程系统,退出)。
设置 acknowledge="transacted"
以便处理中的消息回滚到队列中。