ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » General Discussion » How to loop through all the messages in the queue...

Post new topic  Reply to topic
 How to loop through all the messages in the queue... « View previous topic :: View next topic » 
Author Message
jamesgeorgem
PostPosted: Mon Feb 15, 2010 3:11 pm    Post subject: How to loop through all the messages in the queue... Reply with quote

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
View user's profile Send private message
mvic
PostPosted: Mon Feb 15, 2010 3:31 pm    Post subject: Re: How to loop through all the messages in the queue... Reply with quote

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
View user's profile Send private message
jamesgeorgem
PostPosted: Mon Feb 15, 2010 3:50 pm    Post subject: Re: How to loop through all the messages in the queue... Reply with quote

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
View user's profile Send private message
Vitor
PostPosted: Mon Feb 15, 2010 3:55 pm    Post subject: Re: How to loop through all the messages in the queue... Reply with quote

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
View user's profile Send private message
mvic
PostPosted: Mon Feb 15, 2010 4:07 pm    Post subject: Re: How to loop through all the messages in the queue... Reply with quote

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
View user's profile Send private message
jamesgeorgem
PostPosted: Mon Feb 15, 2010 4:14 pm    Post subject: Re: How to loop through all the messages in the queue... Reply with quote

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
View user's profile Send private message
edasnarik
PostPosted: Thu Mar 04, 2010 11:58 pm    Post subject: Re: How to loop through all the messages in the queue... Reply with quote

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
View user's profile Send private message
exerk
PostPosted: Fri Mar 05, 2010 12:57 am    Post subject: Re: How to loop through all the messages in the queue... Reply with quote

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
View user's profile Send private message
edasnarik
PostPosted: Fri Mar 05, 2010 1:36 am    Post subject: Reply with quote

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
View user's profile Send private message
exerk
PostPosted: Fri Mar 05, 2010 1:43 am    Post subject: Reply with quote

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
View user's profile Send private message
edasnarik
PostPosted: Fri Mar 05, 2010 2:14 am    Post subject: Reply with quote

Acolyte

Joined: 10 Mar 2009
Posts: 61

Yes Exactly ! after one Get.
Back to top
View user's profile Send private message
exerk
PostPosted: Fri Mar 05, 2010 2:19 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General Discussion » How to loop through all the messages in the queue...
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.