Affichage des articles dont le libellé est proccess it then delete it. Afficher tous les articles
Affichage des articles dont le libellé est proccess it then delete it. Afficher tous les articles

jeudi 5 novembre 2015

Exclusive access to read a message from Websphere MQ 7, proccess it then delete it

Vote count: 0

I have a queue form which i'd like to be able to retrieve message. I then need to process them somehow (not in the scope) and then remove them from the queue.

I tried to create 2 queues, one that browse the message and one to delete the message after it has been processed.

    MQQueue browseQueue = qMgr.AccessQueue(QUEUE_NAME, MQC.MQOO_BROWSE);
    MQGetMessageOptions browseOptions = new MQGetMessageOptions()
    {
        Options = MQC.MQGMO_WAIT | MQC.MQPMO_FAIL_IF_QUIESCING | MQC.MQGMO_BROWSE_NEXT,
        WaitInterval = MQC.MQWI_UNLIMITED
    };

    MQQueue acknowledgeQueue = qMgr.AccessQueue(QUEUE_NAME, MQC.MQOO_INPUT_AS_Q_DEF);
    MQGetMessageOptions acknowledgeOptions = new MQGetMessageOptions()
    {
        Options = MQC.MQGMO_WAIT | MQC.MQPMO_FAIL_IF_QUIESCING | MQC.MQMO_MATCH_MSG_ID,
        WaitInterval = MQC.MQWI_UNLIMITED
    };

    while (keepRunning.WaitOne(0))
    {
        MQMessage browseMessage = new MQMessage();

        try
        {
            browseQueue.Get(browseMessage, browseOptions);
        }
        catch (MQException mqexe)
        {
            throw;
        }

        if (browseMessage.MessageType != ShutDown.TYPE)
        {
            object o = browseMessage.ReadObject();
            Console.WriteLine("The message is: {0}", o);
        }

        browseMessage.ClearMessage();

        MQMessage acknowledgeMessage = new MQMessage()
        {
            MessageId = browseMessage.MessageId
        };
        acknowledgeQueue.Get(acknowledgeMessage, acknowledgeOptions);
    }

But I need to make sure no other process can access the same message. Since, I relied on using 2 queues, I don't see how to do it.

asked 1 min ago

This entry passed through the Full-Text RSS service - if this is your content and you're reading it on someone else's site, please read the FAQ at http://ift.tt/jcXqJW.



Exclusive access to read a message from Websphere MQ 7, proccess it then delete it