Author |
Message
|
jamesgeorgem |
Posted: Mon Feb 15, 2010 3:11 pm Post subject: How to loop through all the messages in the queue... |
|
|
Newbie
Joined: 07 Feb 2010 Posts: 7
|
Hi Friends,
I am using Java MQ classes to fetch the data from the message queue by importing
com.ibm.mq.*
I am able to get each messages by specifying the message id, but how can i loop through all the messages in the queue without specifying the message id.
As in my case messageid not available upfront so looping the through the queue is the only solution for me...So if anybody have any sample code which have a loop code, please share with me.
Thanks and Regards,
JG |
|
Back to top |
|
 |
mvic |
Posted: Mon Feb 15, 2010 3:31 pm Post subject: Re: How to loop through all the messages in the queue... |
|
|
 Jedi
Joined: 09 Mar 2004 Posts: 2080
|
The fastest and best way for a getter program to use MQ is to get the next message from the queue. So, if possible (see below) specify no message id, no correl id, nothing. Just get the next message.
If this is not an option in your environment, please tell us some details about why not. (Don't post business sensitive information, of course!) |
|
Back to top |
|
 |
jamesgeorgem |
Posted: Mon Feb 15, 2010 3:50 pm Post subject: Re: How to loop through all the messages in the queue... |
|
|
Newbie
Joined: 07 Feb 2010 Posts: 7
|
mvic wrote: |
The fastest and best way for a getter program to use MQ is to get the next message from the queue. So, if possible (see below) specify no message id, no correl id, nothing. Just get the next message.
If this is not an option in your environment, please tell us some details about why not. (Don't post business sensitive information, of course!) |
Hi mvic,
Thanks for your comments.
As the per my environment, we are having a complex environment where the initiator of the message and the receivers are having different environments and I cannot get the (message id)data direct from him. so he will be dumping the data to Queue and I will process the data accordingly.
It will be great if you provide me some links where sample code is present for finding the next message.
and I Love this forum as the replies are very fast..
Thanks and Regards,
JG |
|
Back to top |
|
 |
Vitor |
Posted: Mon Feb 15, 2010 3:55 pm Post subject: Re: How to loop through all the messages in the queue... |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
jamesgeorgem wrote: |
It will be great if you provide me some links where sample code is present for finding the next message.
|
Try the sample code that's installed (or at least available) with the queue manager or the link helpfully titled "Sample Code" at the top of this page...  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mvic |
Posted: Mon Feb 15, 2010 4:07 pm Post subject: Re: How to loop through all the messages in the queue... |
|
|
 Jedi
Joined: 09 Mar 2004 Posts: 2080
|
jamesgeorgem wrote: |
It will be great if you provide me some links where sample code is present for finding the next message. |
Try Vitor's ideas.. I don't know much about Java and so don't use those resources.
You said you already had written a program to get a message. To get the next message, you just need to get, specifying no message id, no correl id, nothing. Just get from the queue and MQ will give you the next message. |
|
Back to top |
|
 |
jamesgeorgem |
Posted: Mon Feb 15, 2010 4:14 pm Post subject: Re: How to loop through all the messages in the queue... |
|
|
Newbie
Joined: 07 Feb 2010 Posts: 7
|
mvic wrote: |
jamesgeorgem wrote: |
It will be great if you provide me some links where sample code is present for finding the next message. |
Try Vitor's ideas.. I don't know much about Java and so don't use those resources.
You said you already had written a program to get a message. To get the next message, you just need to get, specifying no message id, no correl id, nothing. Just get from the queue and MQ will give you the next message. |
Hi mvic,
I appreciate your inputs to resolve my issue.
I got the intended results by doing a while true loop..which was available in the link
http://www.coderanch.com/t/74447/Websphere/Connecting-MQ-Series-from-java
The below code works fine for me...and the issue is resolved...
while (true) {
MQMessage testRes = new MQMessage();
inQueue.get(testRes);
System.out.println("Received message : "+ testRes.readLine());
}
Thanks and Regards,
JG |
|
Back to top |
|
 |
edasnarik |
Posted: Thu Mar 04, 2010 11:58 pm Post subject: Re: How to loop through all the messages in the queue... |
|
|
Acolyte
Joined: 10 Mar 2009 Posts: 61
|
jamesgeorgem wrote: |
The below code works fine for me...and the issue is resolved...
while (true) {
MQMessage testRes = new MQMessage();
inQueue.get(testRes);
System.out.println("Received message : "+ testRes.readLine());
} |
Do we, for sure , need to create a new MQMessage each time ? and then only can get the message
Cos I see MQJE001: Completion Code 2, Reason 2033 returned if a new message is not created inside the loop.
If it were declared before the loop, it is throwing me the same error as above. |
|
Back to top |
|
 |
exerk |
Posted: Fri Mar 05, 2010 12:57 am Post subject: Re: How to loop through all the messages in the queue... |
|
|
 Jedi Council
Joined: 02 Nov 2006 Posts: 6339
|
edasnarik wrote: |
jamesgeorgem wrote: |
The below code works fine for me...and the issue is resolved...
while (true) {
MQMessage testRes = new MQMessage();
inQueue.get(testRes);
System.out.println("Received message : "+ testRes.readLine());
} |
Do we, for sure , need to create a new MQMessage each time ? and then only can get the message
Cos I see MQJE001: Completion Code 2, Reason 2033 returned if a new message is not created inside the loop.
If it were declared before the loop, it is throwing me the same error as above. |
And does it give a 2033 immediately, or after one GET? _________________ It's puzzling, I don't think I've ever seen anything quite like this before...and it's hard to soar like an eagle when you're surrounded by turkeys. |
|
Back to top |
|
 |
edasnarik |
Posted: Fri Mar 05, 2010 1:36 am Post subject: |
|
|
Acolyte
Joined: 10 Mar 2009 Posts: 61
|
Yes Exactly ! after one Get.
Last edited by edasnarik on Fri Mar 05, 2010 1:48 am; edited 1 time in total |
|
Back to top |
|
 |
exerk |
Posted: Fri Mar 05, 2010 1:43 am Post subject: |
|
|
 Jedi Council
Joined: 02 Nov 2006 Posts: 6339
|
edasnarik wrote: |
Yes Exactly ! |
Yes Exactly after one GET, or Yes Exactly immediately, i.e. on the first GET? _________________ It's puzzling, I don't think I've ever seen anything quite like this before...and it's hard to soar like an eagle when you're surrounded by turkeys. |
|
Back to top |
|
 |
edasnarik |
Posted: Fri Mar 05, 2010 2:14 am Post subject: |
|
|
Acolyte
Joined: 10 Mar 2009 Posts: 61
|
Yes Exactly ! after one Get. |
|
Back to top |
|
 |
exerk |
Posted: Fri Mar 05, 2010 2:19 am Post subject: |
|
|
 Jedi Council
Joined: 02 Nov 2006 Posts: 6339
|
edasnarik wrote: |
Yes Exactly ! after one Get. |
Then think about why that is happening. What is the difference about new MQMessage() within the loop to new MQMessage() outside of the loop? _________________ It's puzzling, I don't think I've ever seen anything quite like this before...and it's hard to soar like an eagle when you're surrounded by turkeys. |
|
Back to top |
|
 |
|