简体   繁体   中英

IBM.XMS IMessageConsumer - won't release - Can't unsubscribe

First: the issue I am unable to successfully do these steps on an asynchronous durable subscriber against ibm's mq topics.

IMessageConsumer.MessageListener = null;
IMessageConsumer.Close();
IMessageConsumer.Dispose();
ISession.Unsubscribe(topicPath);

I get IBM.WMQ.MQException {"2428"} "Failed to unsubscribe from topic X using MQCLOSE. There might have been a problem removing the subscription because it is being used by a message consumer. Make sure any message consumers using this subscription are closed before unsubscribing. Please see the linked exception for more information."

Second: Specifics So I'm using IBMs MQ infrastructure. Specifically their Topic implementation for distributed publisher/subscriber implementation. I'm wrapping the whole thing in a .NET WEB API (MVC5) project to abstract from the rest of the organization all the MQ specifics. For the moment ignore all fail over, etc stuff. When a client calls in I first see if we have an ISession for the caller. If we do I use the existing, if not I make a new from a shared connection factory. Then I create a new destination for consumer. Next I create durable subscription for the specific topic path. Then I add a MessageListener and add the whole mess to an in memory cache. Other tracking also occurring but not important to this discussion.

using IBM.XMS;

// Subscribe
MQConnectionFactory f = (MQConnectionFactory)fact;
SessionClass newSession = new SessionClass(); // Contains an ISession, IDestination, IMessageConsumer

newSession.Session = f.CreateSession();
newSession.Destination = newSession.Session.CreateTopic(MQConnectionFactory.FormatTopic(path));
newSession.Consumer = newSession.Session.CreateDurableSubscriber(newSession.Destination, subId.ToString());
newSession.Consumer.MessageListener = new MessageListener(MessageHandler);


// Message Handler - Some "details" removed
private void MessageHandler(IMessage msg)
{
    string topic = msg.GetStringProperty(MQConstants.TOPIC);
    DateTime timestamp = DateTime.FromBinary(msg.GetLongProperty(MQConstants.DATETIME));
    List<KeyValuePair<string, object>> parms = msg.GetStringProperty(MQConstants.PARAMETERS).FromBase64();
    object payload = msg.GetObjectProperty(MQConstants.PAYLOAD);

    Publication publication = new Publication()
    {
        MessageTimestamp = timestamp,
        Topic = topic,
        Parameters = parms
    };

    Callback.Notify(publication))
    _log.DebugFormat("Message delivered to {0}", msg.JMSMessageID);
    msg.Acknowledge();
}

// And for unsubscribe
SessionClass s = _destinations[fullPath];
s.Consumer.MessageListener = null;
s.Consumer.Close();
s.Consumer.Dispose();
s.Session.Unsubscribe(s.Destination.Name);
_destinations.Remove(fullPath);

So all the subscribe and message handling works fine. The UnSubscribe always fails when I hit the

s.Session.Unsubscribe(s.Destination.Name) 

saying it's "in use" basically. I've attempted Stopping the connection prior to the unsubscribe to no effect as well.

Anyone have any ideas? I'm completely unable to remove any subscriptions from MQ after creating them as a result.

thanks

So after reviewing documentation more and consulting more with other people it's a matter of not the most clear MQ documentatin.

What needs passed to the Unsubscribe method is the ID passed to the CreateDurableSubscriber method

So....using the code above the only change is to the Unsubscribe call.

s.Session.Unsubscribe(subId.ToString());

And then all is good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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