gpt4 book ai didi

java - Spring Integration 轮询器在一段时间后挂起或停止

转载 作者:行者123 更新时间:2023-12-01 10:20:00 25 4
gpt4 key购买 nike

我有一个应用程序可以读取来自 HornetQ 的 JMS 消息。

<int-jms:message-driven-channel-adapter
id="myJmsChannelAdapter"
channel="myJmsChannel"
connection-factory="myCredentialsConnectionFactory"
destination-name="${my.jms.topic}"
pub-sub-domain="true"
subscription-durable="${my.jms.subscription.durable}"
client-id="${my.jms.client.id}"
durable-subscription-name="${my.jms.subscription.name}"
/>

当消息到达时,我通过轮询器处理它们

<!-- Send Jms message one by one to creation -->
<int:bridge input-channel="myJmsChannel" output-channel="jmsMessageCreateInputChannel">
<int:poller max-messages-per-poll="1" fixed-delay="100">
<int:transactional transaction-manager="transactionManager" propagation="REQUIRES_NEW"/>
</int:poller>
</int:bridge>

轮询器调用一个链,将消息的内容存储在我的数据库中

<chain id="jmsMessageCreate" input-channel="jmsMessageCreateInputChannel">
<!-- extract the operation from the message itself -->
<int-xml:xpath-header-enricher>
<int-xml:header name="operation" xpath-expression="name(./node())" overwrite="true"/>
</int-xml:xpath-header-enricher>

<service-activator expression="@jmsMessageService.createNewJmsMessage(payload, headers['operation'])"/>
<!-- have a JPA entity in the payload -->
<gateway request-channel="persistEntityChannel"/>
<logging-channel-adapter logger-name="JmsLogger" expression="'JMS message with operation ['+headers['operation']+'] created in DB'"/>
</chain>

我的问题如下,有时,没有明显的原因并且日志中没有任何错误消息,我的消息不再被处理。链 ID jmsMessageCreate 不再被调用,就像轮询器停止工作一样。如果服务器重新启动,它会再次正常工作,但我丢失了在轮询器停止和服务器重新启动之间发送的 JMS 消息。

我真的不知道该去哪里寻找或采取什么措施来防止这种情况发生。也许配置发生变化?

预先感谢您的帮助。

最佳答案

轮询器线程很可能“卡在”代码中的某个地方。使用jstack <pid>进行线程转储以查看线程正在做什么。您可以使用jps找到 pid。

为了避免丢失消息,您应该设置 acknowledge="transacted"在消息驱动适配器上 - 这已更改为默认值 true在 4.2 版本中。

您不应该在此环境中使用 QueueChannels 和轮询器 - 线程由消息驱动适配器管理。使用队列 channel ,即使使用事务处理 session ,容器也会在消息放入队列后立即提交。

关于java - Spring Integration 轮询器在一段时间后挂起或停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35657508/

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