【发布时间】:2022-06-24 17:52:10
【问题描述】:
我正在使用 connection.start() 来启动连接,并使用 consumer.receive() 来接收来自队列的消息。但是在关闭连接时,它无法使用 connection.close() 关闭连接。因此,它会耗尽连接限制并引发队列管理器不可用的异常。
这背后的原因是什么?以及如何解决?
connectionWMQ = connectionFactory.CreateConnection();
connectionWMQ.ExceptionListener = new ExceptionListener(OnXMSException);
// Create session
ISession sessionWMQ = connectionWMQ.CreateSession(false, AcknowledgeMode.AutoAcknowledge);
IDestination destination = sessionWMQ.CreateQueue("QueueName");
IMessageConsumer consumer=sessionWMQ.CreateConsumer(destination);
try{
connectionWMQ.Start();
var message=(IMessage)Consumer.Receive(TIMEOUTTIME);
//decoding the msg;
connectionWMQ.Close();
}
catch(Exception ex){
}
【问题讨论】:
-
查看您提到的方法名称,您正在使用 XMS。网络核心。什么是版本? connection.close() 关闭在该连接下创建的所有打开对象——即消费者、生产者和会话。由于某种原因,您的应用程序中可能没有调用 connection.close !你能用代码更新问题吗?
-
@Shashi 我使用的是 IBM XMS 版本 9.2.0.4。我已经测试过,每次打开连接以接收消息时它都会调用 connection.close()。
-
连接打开和关闭的频率如何?您是否对每条消费的消息都这样做?
-
@Shashi 是的。我正在使用 Windows 服务。
-
解决方案是什么。你可以自己写答案。