I am a newbie on IBM WebSphere MQ, and recently have to write some MQ codes in C# and Windows environment. Some of the codes were just copied/paste from IBM site examples. I have some hanging problem which makes me very frustrated. Here is the situation:
Customer keeps sending the message in a fast pace through IBM WebSphere MQ (or MQSeries), about one message every 1 or 2 seconds. Each message is about 100 KB ~ 1 MB size. On our receiving side, I need to write a C# program to receive the messages, process it. The logic is: When our MQ gets a message, it triggers an event to order to start a new thread to get the message. Attached below are some pseudo codes on how to get the message. If success, we should get and process 2000 queue messages. But when we get around 500 queues, the program starts hanging. My question: Is there any problem on the following code? Is there any problem on the While loop? I suspect it might be the while loop got hung. MQC.MQGMO_BROWSE_NEXT is to get next queue. If it is in the end of queue, does myQueue.Get(mqMsg, oOptions) will throw the exception?
MQGetMessageOptions mqGetMsgOpt; mqGetMsgOpt = new MQGetMessageOptions();
//open the queue mqGetMsgOpt.Options = MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_BROWSE;
//we know the queuePath myQueue = myQueueManager.AccessQueue(queuePath, mqGetMsgOpt.Options);
MQGetMessageOptions oOptions = new MQGetMessageOptions(); oOptions.Options = MQC.MQGMO_BROWSE_FIRST;
//loop through messages MQMessage mqMsg = new MQMessage();
// This will loop until the matching message is found or an exception is thrown at the // end of the queue having not found the message to be delivered while (1>0) { myQueue.Get(mqMsg, oOptions);
//Get the MessageId string msgID = ""; for (int x = 0; x < mqMsg.MessageId.Length; ++x) { msgID += Convert.ToString(mqMsg.MessageId[x]); }
//Check to see if the messageID is the ID we want if (msgID != MsgIDWeWant) //The trigger event passes the MsgIDWeWant { oOptions.Options = MQC.MQGMO_BROWSE_NEXT; continue; }