What is the best way to pull the messages from MQ queue.

I have written a C# Win service to pull the messages from Websphere MQ queue. I have a question here on the approach to be followed.

1. Open the connection only once to the queue and pull all the messages and keep checking for the messages forever and never close the connection.

2. Establish the connection to queue and then pull the message and then close it immediately. And do the same for every message.

What is the best way? And why?

I have opeted the 2nd one, but one of my friend suggest the 1st one. Please suggest me which is the best way.
GouthamAnandAsked:
Who is Participating?
 
Gary PattersonConnect With a Mentor VP Technology / Senior Consultant Commented:
In a high-volume application, option 1 is probably "more right".

Repeatedly opening and closing a connection creates overhead on both the client and the server.

When using this model, you'd MQGET with a relatively long or unlimited timeout interval (read the docs if you use MQ from IMS apps).  MQGET blocks on an empty queue, so you don't burn a lot of CPU while waiting for the next entry.  If you MQGET with a short timeout, you burn a lot of cycles dealing with NO_MSG_AVAILABLE.

Only close if you are shutting the application down or need to disconnect for some reason.

In a low volume application, it doesn't make that much difference, but remember that low-volume applications have a tendency to occasionally and suddenly become high volume applications.
0
 
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
I would go with the first option as there is no need to keep connecting and disconnecting, plus the is a lot of additional overhead with doing so. I'd only consider closing the connection each time if there is any chance of hitting the concurrent connection limit.
0
 
Easwaran ParamasivamConnect With a Mentor Commented:
It depends. If your frequency to hit MSMQ is less then go for second option. Otherwise choose first option.

One more point is that if your MSMQ is being modified rarely then better save the result of first hit in a Cache object. So that you no need to read each time the MSMQ.

Analyze based on your requirement and go for it. There is no hard rule to say which one is correct approach.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
lgacsConnect With a Mentor Commented:
Previous comments are correct, but ...

If the queue manager is remote, you must manage connection failures in case 1 or choose case 2 if performance is not a key issue.
0
 
Gary PattersonVP Technology / Senior Consultant Commented:
Why would you design-in poor performance to an application?
0
 
lgacsCommented:
Reliability first !
0
 
GouthamAnandAuthor Commented:
Thanks a lot to every one for replying to my question.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.