Search code examples
c#listeneribm-mqmq

C# Listener Making IBM MQ Message Cleared Automatically


I have a C# listener for IBM MQ like below. Only listener method mentioned here.

private void OnMessage(IMessage msg)
{
    try
    {

        ITextMessage textMsg = (ITextMessage)msg;
        Console.Write("Got a message: ");
        Console.WriteLine(textMsg.Text);

    }
    catch(Exception ex)
    {
    }
}

Whenever a text format message has been reached in side my queue, above listener is invoking and i am able to read values.

Problem is that if you stop the listener and then push a message, that message is retaining in MQ Explorer. But if the listener method has been invoked, the message has been deleting from "Web Sphere MQ Explorer" always just after read from the listener method. Do I need to set some more configuration to retain my messages even after my listener read it?


Solution

  • That is the expected behavior. The message in a queue is being consumed by an application (meaning your OnMessage method). WebSphere MQ will deliver the message to a waiting consumer application as soon as the message arrives in queue.

    If you want to messages to remain in the queue, then you need to stop all your consumer application.