Advertisement

01.30.2008 at 11:40AM PST, ID: 23124019 | Points: 200
[x]
Attachment Details

MQ Listening Service Program use MQQueue::Get?

Tags: IBM, IBM WebSphere MQ, C#
Hi, IBM WebSphere MQ guru,

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?

Thank you for the help.

              &&

            MQQueue myQueue = null;
            MQQueueManager myQueueManager = null;
            try
            {
                &&

                myQueueManager = new MQQueueManager();

                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;
                    }

                    oOptions.Options = MQC.MQGMO_MSG_UNDER_CURSOR;
                    myQueue.Get(mqMsg, oOptions);

                    //Save the message to a stream and process it
                    &&
                    break;
                } // while not out of messages

                myQueue.Close();
            }
            catch (MQException mqe)
            {
                //process some error messages
                &&
                throw mqe;
            }
            catch (Exception e)
            {
                //process some error messages
                &&
                throw e;

            }
            finally
            {
                //close the queue
                if (myQueue != null && myQueue.IsOpen)
                {
                    myQueue.Close();
                }

                //disconnect the Queue Manager
                if (myQueueManager != null && myQueueManager.IsConnected)
                {
                    myQueueManager.Disconnect();
                }
            }
Start your free trial to view this solution
Question Stats
Zone: Software
Question Asked By: suwanee
Question Asked On: 01.30.2008
Participating Experts: 1
Points: 200
Views: 0
Translate:
Loading Advertisement...
01.31.2008 at 12:34AM PST, ID: 20784886

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.01.2008 at 07:15AM PST, ID: 20797133

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.01.2008 at 07:27AM PST, ID: 20797281

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.01.2008 at 07:30AM PST, ID: 20797328

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080236-EE-VQP-29 / EE_QW_2_20070628