简体   繁体   English

发生异常后,我们如何从系统中正确关闭和清理 JMS 连接、Session、消费者和生产者?

[英]How can we close and clean properly JMS Connection, Session, Consumer and Producer from system after Exception?

We are using Apache Qpid JMS Client(0.45) to consume messages from ServiceBus.我们正在使用 Apache Qpid JMS Client(0.45) 来使用来自 ServiceBus 的消息。 We are getting Suspected deadlocked threads while restarting of connection.重新启动连接时,我们收到了可疑的死锁线程 After log investigation, we realized that JmsSession was not closed properly.经过日志调查,我们发现 JmsSession 没有正常关闭。 While closing JmsSession - we received Illegal invocation from MessageListener callback error.关闭 JmsSession 时 - 我们收到来自 MessageListener 回调错误的非法调用 It could be a reason for thread blocking.这可能是线程阻塞的原因。

If we received an exception while closing JMS Connection/Session/Consumer, then how can we close and clean up properly from system?如果我们在关闭 JMS Connection/Session/Consumer 时收到异常,那么我们如何才能从系统中正确关闭和清理呢?

I reset JMS object after closing such as Connection = null, MessageConsumer=null; Session = null;我在关闭后重置 JMS object 例如Connection = null, MessageConsumer=null; Session = null; Connection = null, MessageConsumer=null; Session = null; . . I think this is not working properly as some Threads are still open in System.我认为这不能正常工作,因为某些线程仍然在 System.

Could anyone please suggest any idea to clean and close JMS object properly from System?谁能建议任何想法从系统中正确清理和关闭 JMS object?

Sample deadlock log示例死锁日志

Suspected deadlocked threads: JmsSession [ID:7086e194-aaec-4b41-cde1-fd680526e07a:1:12] delivery dispatcher Id=201 is in WAITING on lock=java.util.concurrent.locks.ReentrantLock$NonfairSync@20af281a疑似死锁线程:JmsSession [ID:7086e194-aaec-4b41-cde1-fd680526e07a:1:12] Delivery Dispatcher Id=201 is in WAITING on lock=java.util.concurrent.locks.ReentrantLock$NonfairSync@20af281a
is owned by JmsSession [ID:7086e194-aaec-4b41-cde1-fd680526e07a:1:10] delivery dispatcher Id=199 |归 JmsSession 所有 [ID:7086e194-aaec-4b41-cde1-fd680526e07a:1:10] 交付调度程序 Id=199 | JmsSession [ID:7086e194-aaec-4b41-cde1-fd680526e07a:1:10] delivery dispatcher Id=199 is in BLOCKED on lock=org.mule.transport.Servicebus@778245e1 JmsSession [ID:7086e194-aaec-4b41-cde1-fd680526e07a:1:10] 交付调度程序 Id=199 在 lock=org.mule.transport.Servicebus@778245e1 上处于阻塞状态
is owned by JmsSession [ID:7086e194-aaec-4b41-cde1-fd680526e07a:1:12] delivery dispatcher Id=201 |归 JmsSession [ID:7086e194-aaec-4b41-cde1-fd680526e07a:1:12] 交付调度程序 Id=201 | 所有" "

As per the JMS specification calling Connection.close() will close all client resources and shutdown all client threads once the close completes.根据 JMS 规范,调用 Connection.close() 将关闭所有客户端资源并在关闭完成后关闭所有客户端线程。 There isn't a need to close each individual resource unless you are doing something to try and recreate a failed consumer or producer but in the end it is hard to tell from the generic JMS exceptions what has gone wrong so you likely will end up closing the connection and starting over as the most robust means of error recovery.除非您正在尝试重新创建失败的消费者或生产者,否则无需关闭每个单独的资源,但最终很难从通用 JMS 异常中判断出了什么问题,因此您可能最终会关闭连接和重新开始是最可靠的错误恢复方式。

You are using a rather old JMS client version as the latest is 0.55.0 with a 0.56.0 likely being released in a week or two.您使用的是相当旧的 JMS 客户端版本,因为最新版本是 0.55.0,而 0.56.0 可能会在一两周内发布。 There are a number of fixes between where you are now and what's currently available so you really should update before chasing after things that are likely fixed.在您现在所在的位置和当前可用的位置之间有许多修复,因此您真的应该在追逐可能修复的东西之前进行更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM