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 » IBM MQ Java / JMS » Traversing messages in Queue.

Post new topic  Reply to topic Goto page 1, 2  Next
 Traversing messages in Queue. « View previous topic :: View next topic » 
Author Message
Rohit_
PostPosted: Mon Sep 08, 2008 11:39 am    Post subject: Traversing messages in Queue. Reply with quote

Novice

Joined: 10 Jan 2008
Posts: 24

Hi Group,

I want to traverse (Browse) the messages in queue.
After last message,an exception is thrown.

what option I can use to make a check on this?
After every message i read,i reset the get message option.

gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_NEXT;

but I also want to do a check for "end of message".user will just invoke the method to browse,so there will be no input from message.

thanks.
Back to top
View user's profile Send private message
bower5932
PostPosted: Mon Sep 08, 2008 12:14 pm    Post subject: Reply with quote

Jedi Knight

Joined: 27 Aug 2001
Posts: 3023
Location: Dallas, TX, USA

If I understand what you are saying, you are experiencing normal behavior. WMQ gives you the 2033 return code to let you know that there is no message available. You can look at the amqsbcg0.c sample to see what it does with this return code.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
Rohit_
PostPosted: Mon Sep 08, 2008 12:25 pm    Post subject: Reply with quote

Novice

Joined: 10 Jan 2008
Posts: 24

bower5932,

Yes it's throwing 2033.Actually am browsing the queue,and fetching the messages and putting up in a list. My aim is to return the list ,which is containg 'n ' messages.

Now before I can return the list ,an exception is thrown.

So i am looking a way where i can predetermine the size of queue( hoqw many message it has).so that i traverse for only that size.

the way we read a file till EOF occurs.how I can do that?

thanks in advance
Back to top
View user's profile Send private message
PeterPotkay
PostPosted: Mon Sep 08, 2008 12:38 pm    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

Rohit_ wrote:
So i am looking a way where i can predetermine the size of queue( hoqw many message it has).so that i traverse for only that size.

Don't do that. Lots of discussions here on why this is a very, very bad idea.

Rohit_ wrote:
the way we read a file till EOF occurs.how I can do that?

Keep doing MQGETs until you get a 2033 MQRC.
_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon Sep 08, 2008 1:51 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

PeterPotkay wrote:
Rohit_ wrote:
So i am looking a way where i can predetermine the size of queue( hoqw many message it has).so that i traverse for only that size.

Don't do that. Lots of discussions here on why this is a very, very bad idea.

Rohit_ wrote:
the way we read a file till EOF occurs.how I can do that?

Keep doing MQGETs until you get a 2033 MQRC.

And remember when you browse to clear the MsgId and CorrelId between 2 gets.
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Rohit_
PostPosted: Tue Sep 09, 2008 5:39 am    Post subject: Reply with quote

Novice

Joined: 10 Jan 2008
Posts: 24

Does MQ can support below scenario?

Say, server1 reads 5 messages from a queue(no logical grouping). then after 1 hr another 3 messages come. now method is invoked on server1, again to read the messages. now can I avoid reading previous 5 messages. I just want new 3 messages and that too with removing them.

and another server2 invoked and will go and read 8 messages(because,it fetching for the first time)

thanks in advace.
Back to top
View user's profile Send private message
bower5932
PostPosted: Tue Sep 09, 2008 6:13 am    Post subject: Reply with quote

Jedi Knight

Joined: 27 Aug 2001
Posts: 3023
Location: Dallas, TX, USA

This also sounds like 'normal wmq' behavior. You have a program sitting on an mqget on a queue. It gets the first five messages and then gets the 2033 (no msgs available). It then goes back to get the next message (maybe with a longer delay?) and has to wait 1 hour. It then gets 3 messages and get another 2033.

You might want to consider triggering the program that reads the queue if your example is typical. You usually don't have a program sitting around for long periods of time waiting for messages.

If server2 isn't running, when it comes up, it will get all 8 messages.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
Rohit_
PostPosted: Tue Sep 09, 2008 8:09 am    Post subject: Reply with quote

Novice

Joined: 10 Jan 2008
Posts: 24

But my server goes in sleep awake mode. sleep means, disconnected from Queue Manager.So first time it cometo 'awake' mode, it fetches 5 messages and then moved to 'sleep 'mode. after some time it comes to 'awake' mode and it goes to fetch new messages. now it is suppose to get only 3 messages,not old already fetched 5 messages.

am simply doing below operation to do so :

msgReply.clearMessage();
msgReply.correlationId = MQC.MQCI_NONE;
msgReply.messageId = MQC.MQMI_NONE;

m_queue.get(msgReply, gmo);

String msg = sgReply.readStringOfCharLengthsgReply.getMessageLength());
gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_NEXT;

I wonder what option to use,so that MQ can track that this IP(server) already fetched(safe read) 5 messages and now here only for new messages.

===============================================

The way MQ do grouping and the way I thought seems to be different(am still not sure).

I thought i can logically divide my queue, Q1 into 3 groups(say, Q11,Q12,Q13) .Now some remote application can put messages (M1->Q11,M2->Q12,M3->Q13) in that groups.

my local application will go and read this messages from group,and retun 3 objects containg messages from each group.

can I design this way?

thanks in advance.
Back to top
View user's profile Send private message
dkeister
PostPosted: Tue Sep 09, 2008 10:49 am    Post subject: Reply with quote

Disciple

Joined: 25 Mar 2002
Posts: 184
Location: Purchase, New York

I think the following is what you are trying to do:

"But my server goes in sleep awake mode. sleep means, disconnected from Queue Manager.So first time it cometo 'awake' mode, it fetches 5 messages and then moved to 'sleep 'mode. after some time it comes to 'awake' mode and it goes to fetch new messages. now it is suppose to get only 3 messages,not old already fetched 5 messages. "

The way browsing works is there is a Browse Cursor that is pointing to the last message browsed (or to just before the first message when you first open a queue for browsing or set the BROWSE_FIRST option).

The queue has five messages 1,2,3,4,5 so after you browse five messages and you try to browse the next message you get a CC of 2033. In this case, the browse cursor is still referencing message 5. After that, if an application puts another three messages on the queue the queue has eight messages). 1,2,3,4,5,6,7,8

If you do not reopen the queue in your browse application and issue a BROWSE_NEXT you will browse message 6 and if in a loop, will also browse 7 and 8 at which point you will again receive a CC of 2033 with the browse cursor pointing to eight message position.

That is how it works, but if you rely on the browse cursor position, I think you might have problems if messages are being removed from the queue while the server is asleep.

Example. With five messages on the queue (1,2,3,4,5) you browse five messages, the server goes to sleep, during the sleep, three messages are put on the queue (1,2,3,4,5,6,7,, but one message is removed from the queue. In this case, there are seven messages on the queue (2,3,4,5,6,7,. However, the browse cursor is still pointing to message position five. If you BROWSE_NEXT at this point, you will browse 7 which is now in the sixth position and message 6 (which is in the fifth position) will not be browsed.

This is the simple case. In other situations, messages may be removed from anywhere in the queue so you might want to rethink the design.
_________________
Dean Keister
Back to top
View user's profile Send private message Send e-mail Visit poster's website
fjb_saper
PostPosted: Tue Sep 09, 2008 7:18 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Like Peter said something is wrong with the design here.
If you are just trying to see how many messages are in the queue you should not be using browse. Use pcf messages to enquire about the queue depth (see support pack MS0B).

The ideal is if you look at the message you should consume it. Otherwise don't bother looking at it. And if you don't need to look at it you should not browse it....

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Rohit_
PostPosted: Wed Sep 10, 2008 5:38 am    Post subject: Reply with quote

Novice

Joined: 10 Jan 2008
Posts: 24

Am browsing because many servers will be hooking up to that queue. so I just need safe read. and also I want non redundant reading of messages.

Also can I logically divide my queue in groups? like while creating the queue or while putting up some messages?

So that while reading ,I just go to particular group and get the message?

Is this supported ?or some better way?
Back to top
View user's profile Send private message
bower5932
PostPosted: Wed Sep 10, 2008 6:08 am    Post subject: Reply with quote

Jedi Knight

Joined: 27 Aug 2001
Posts: 3023
Location: Dallas, TX, USA

Rohit_ wrote:
Am browsing because many servers will be hooking up to that queue. so I just need safe read. and also I want non redundant reading of messages.


Do multiple programs actually need to get the message? Have you considered putting the message multiple times? What about something like mirrorq? I'd want to know some more about the design of what is going on and why.
Rohit_ wrote:
Also can I logically divide my queue in groups? like while creating the queue or while putting up some messages?

So that while reading ,I just go to particular group and get the message?

Is this supported ?or some better way?

You could try using separate queues for each logical group. You mentioned "while creating the queue". Is this something that you need to do often? Should you be looking into dynamic queues? Once again, I'd like to know more about what you are trying to do and why.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
dkeister
PostPosted: Wed Sep 10, 2008 6:30 am    Post subject: Reply with quote

Disciple

Joined: 25 Mar 2002
Posts: 184
Location: Purchase, New York

I too am having difficulty in understanding what you are trying to accomplish from a business perspective.

I think from 'safe read' you mean browse.

Not clear what the need to browse the messages on the queue is, but if other applications are both getting and putting messages during your 'sleep interval' you have no idea the position of the already browsed messages and you have no way of knowing where to start browsing again except to browse from the beginning each time. But since I don't know why you are browsing them in the first place, I can't make any specific suggestions on what to do.

Another question I have is what is the average queue depth? and do you need all the message data when browsing (you might use browse with accept truncated to minimize network bandwidth when browsing each message.

You started this thread by asking how to accomplish a technical function and there are plenty of suggestions already posted. If you described the business requirement, we might be able to provide better suggestions.
_________________
Dean Keister
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Rohit_
PostPosted: Wed Sep 10, 2008 6:40 am    Post subject: Reply with quote

Novice

Joined: 10 Jan 2008
Posts: 24

The main Application say,"App" will place a message on queue,"Q1".Now different servers at different regions need to get this message and has to acknowledge for each and every message
On different queue Q2.now this different servers are basically at different time zones, which need to have access to this messages.

The queue Q1 created currently is persisted and local.

==> Say one of my server is browsing the message, and in last call it read 20 messages. now another 2 messages come and I suppose that it will read next 2 messages, as cursor is was at 20th message.

But what if my server is bounced? after bouncing it will go and read all 22 messages. 20 old and 2 new.now this a major problem here.

My Application,APP send the message. Say ,
For event 1 evt1 msg1.
evt2 msg2.

This is how I want to design :

Can I logically divide my queue this way

Group1 grp 1 will have msg for event 1 that is msg1
grp2 => msg2

Basically am banking on the idea, how hard disk are logically divided and many other examples.

This way it will be very easy to do the things.

This main application App1 and Q1 are some other project, so I don’t have any say in their design. I have to design on the top of there design.

Thanks

please let me know if this make sense.else I'll try to drop more info.
Back to top
View user's profile Send private message
Rohit_
PostPosted: Wed Sep 10, 2008 7:06 am    Post subject: Reply with quote

Novice

Joined: 10 Jan 2008
Posts: 24

bower5932 ,dkeister

Okay apart from my particular application.I want to know if anyone has faced similar scenerio.

Am safe reading messages from queue. My server crashes and now how to figure out where I was before server crash?

I read 2000 messages and only 3 are left.i don’t want to go back and read all 2000 stale messages.

How this situation is handled in MQ?

1)While putting messages if I use some grouping and logical order stuff ?
2) while MQGet I store some information with me in DB.say with every message some <customerid> is unique.
So I store this customer id(customer id is part of my message) and groups id of this message. so after crash I know what I read successfully before crash?
And I can proceed after that.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » IBM MQ Java / JMS » Traversing messages in 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.