Reputation: 485
I have an application that uses WebSphere MQ to send data through WebSphere to a datacentre in the Cloud. Part of the functionality is that if the server-side subscriber detects that a message has not been received for 30 minutes, the thread is paused for 5 minutes, and the connection is removed. When it restarts, it reconnects.
In practice, I've found that disconnecting has not removed the subscription. When attempting to reconnect, I see this error:
"There may have been a problem creating the subscription due to it being used by another message consumer. Make sure any message consumers using this subscription are closed before trying to create a new subscription under the same name. Please see the linked exception for more information."
This shows the message handler is still connected, meaning disconnect has failed. Disconnect code for the XmsClient object (part of the library, although one of my colleagues might have changed it) is:
public override void Disconnect()
{
_producer.Close();
_producer.Dispose();
_producer = null;
_consumer.MessageListener = null;
_consumer.Close();
_consumer.Dispose();
_consumer = null;
_sessionRead.Close();
_sessionRead.Dispose();
_sessionRead = null;
_sessionWrite.Close();
_sessionWrite.Dispose();
_sessionWrite = null;
_connection.Stop();
_connection.Close();
_connection.Dispose();
_connection = null;
//GC.Collect();
IsConnected = false;
}
Anyone have any thoughts as to why the connection still exists?
Upvotes: 2
Views: 893
Reputation: 15283
From the error description it looks like server subscriber is creating a durable subscription. Durable subscription continues to receive messages even when subscribing application is not running. To remove a durable subscription you must call Session.Unsubscribe(). Simply closing the consumer does not remove subscription.
If your intention was to close a subscriber without removing the subscription, then issue Connection.Stop() first followed by deregister message listener and then close consumer. Calling connection.Stop method stops message delivery.
Upvotes: 2