Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# MQ Api How to fetch message without getting exception in case of empty queue

Tags:

c#

ibm-mq

I have to periodically check messages in a queue within Websphere MQ. I haven't found better approach rather than try getting a message and handle 2033 reason code (which is NO_MSG_AVAILABLE) like this:

try
{
    // ...
    inQueue.Get(message);
}
catch (MQException exception)
{
    if (exception.ReasonCode != 2033)
        throw;
}

Is there better way to get message from queue? I think that there might be some openOptions flag that I'm not aware of, that wouldn't throw exception when no message available, but return null instead.

like image 546
koss Avatar asked Dec 16 '22 17:12

koss


1 Answers

There are three ways to avoid or reduce this polling mechanism. Here they are in oder of elegance(the higher the better):

  1. MQGET with wait interval UNLIMITED and MQGMO_FAIL_IF_QUIESCING
  2. Get your application be triggered by MQServer
  3. Callback function - new with MQ V7 on both sides
like image 79
gouda Avatar answered Apr 28 '23 11:04

gouda