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 API Support » Trying to read multiple messages from Queue

Post new topic  Reply to topic
 Trying to read multiple messages from Queue « View previous topic :: View next topic » 
Author Message
Vinay15
PostPosted: Tue Oct 17, 2006 12:45 am    Post subject: Trying to read multiple messages from Queue Reply with quote

Newbie

Joined: 11 Oct 2006
Posts: 6
Location: UK

I am using two applications to read MQ message. First application puts the basic info from Queue to my application database and moves the message on MQ to vetted Queue. Second application then tries to read message from from vetted Queue. The second application uses Queue manager name put in by first application to identify the queue to pick message. My code is working ok for this. But problem comes when I try to read multiple messages from queue bases on message ID. My code is below:
Dim i As Integer
Dim cnt As Integer

While i < 24
If cnt = sMQMessageID.Length Then
Exit While
End If
oMQMessage.MessageId(i) = Decimal.Parse(sMQMessageID.Substring(cnt, 2), Globalization.NumberStyles.AllowHexSpecifier)
cnt = cnt + 2
i = i + 1
End While

Dim oMQ_GMO As MQGetMessageOptions = New MQGetMessageOptions
oMQ_GMO.Options = MQC.MQMO_MATCH_MSG_ID

oMQQueue.Get(oMQMessage, oMQ_GMO)


I want to read multiple messages based om MessageID that I have in sMQMessageID. Pls help me in this.
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Oct 17, 2006 12:52 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

By default all message ids are unique, generated by the queue manager on put. You should not modify this behaviour and if you do you should never have messages with duplicate ids.

If you want to group messages together use the grouping options provided by MQ.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Oct 17, 2006 3:14 am    Post subject: Reply with quote

Grand High Poobah

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

And remember fields like messageId and correlationId or groupId are not strings and not numbers but byte arrays! So don't try to manipulate them as any other type!
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Vinay15
PostPosted: Tue Oct 17, 2006 5:33 am    Post subject: Reply with quote

Newbie

Joined: 11 Oct 2006
Posts: 6
Location: UK

Yes, they all are byte(). But when I read a message from multiple messages on Queue based on MessageId that I have it fetches different message. So I want to know that, where the code wht I have given to read message from message ID goes wrong?
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Tue Oct 17, 2006 5:36 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Message IDs are byte arrays. Almost every attempt to treat them as anything else will be doomed to failure.

In general, you shouldn't plan to pass message IDs between applications, and use those IDs to retrieve messages.

In general, you shouldn't encode business level information into message IDs or any other field in the MQMD.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Oct 17, 2006 5:42 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Vinay15 wrote:
Yes, they all are byte(). But when I read a message from multiple messages on Queue based on MessageId that I have it fetches different message. So I want to know that, where the code wht I have given to read message from message ID goes wrong?


You say you're trying to read a message based on a message id that you have - do you mean a reply to a message that you sent? If so, are you sure that the reply doesn't have "your" message id in the correlation id? That's the standard and recommended way of doing request/reply - create a new message id (because it should be a unique value) and put the original id into the correlation. Is it therefore possible you're looking at the wrong field? Or is it more possible I've misunderstood what you're trying to do?
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Vinay15
PostPosted: Tue Oct 17, 2006 7:50 am    Post subject: Reply with quote

Newbie

Joined: 11 Oct 2006
Posts: 6
Location: UK

Hi, Thanks for the replay. Let me be a bit more specific.

I am not giving replay to a message. As I have explained in first part, there are two applications which reads the message from Queue. First application reads Queue Manager name and MessageID for the message and put the message in vetted Queue. Then triggers second application. This in turn goes to the MQ Manager and then with the provided MessageID tries to read message from vetted Queue.

With the code in first part it works ok for single message on queue. But for multiple messages it picks up wrong message. but I need the application to read correct message from multiple one.

Please help me in this.
Back to top
View user's profile Send private message
kevinf2349
PostPosted: Tue Oct 17, 2006 8:13 am    Post subject: Reply with quote

Grand Master

Joined: 28 Feb 2003
Posts: 1311
Location: USA

Quote:
First application reads Queue Manager name and MessageID for the message and put the message in vetted Queue.


....at which point the MessageID will get changed on the 'vetted' queue message won't it?
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Tue Oct 17, 2006 8:14 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

jefflowrey wrote:
In general, you shouldn't plan to pass message IDs between applications, and use those IDs to retrieve messages.


You're building an unnecessary coupling between your two applications.

There's no reason for either of them to know what message ID the other is using before the message is produced or consumed, nor for either of them to communicate using anything other than MQ if they are going to communicate by MQ at all.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Oct 17, 2006 8:19 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

So there are multiple messages read by first application, it reads the messages and puts the ones it passes onto a vetted queue. It retains this message id, passes this to a second application which then tries to use this message id to pick off the message from the vetted queue.

So why is the second application not reading eveything off the vetted queue and processing them all irrespective of message id? How does the second program get the message id from the first one & why not send the vetted details? Don't get it...

Assuming there is a good reason for this design that I've failed to grasp (more than possible) I'd theorise that the second application doesn't clear down it's matching options before doing the read, and so selects the wrong message.

This also sounds a lot like you have message affinity in your solution. This is bad and not recommended.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
kevinf2349
PostPosted: Tue Oct 17, 2006 8:40 am    Post subject: Reply with quote

Grand Master

Joined: 28 Feb 2003
Posts: 1311
Location: USA

Quote:
Don't get it...


Me neither, but I am sort of assuming they are trying to build a database that is a list valid messages and from where they came, but I am not 100% sure why. Maybe it is some auditing requirement?

What I can't understand is why the need to pass the msgid to the program at all. I think I would just simply only allow validated message through the first program and then those that arrive on a 'vetted' queue just process everyone of those suckers.
Back to top
View user's profile Send private message
Vinay15
PostPosted: Mon Oct 23, 2006 1:58 am    Post subject: Reply with quote

Newbie

Joined: 11 Oct 2006
Posts: 6
Location: UK

Is there any other way to match Message ID
Back to top
View user's profile Send private message
Vitor
PostPosted: Mon Oct 23, 2006 2:08 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Short answer: No.

Medium answer: No. IBM only built the GMO_MATCH_MSG_ID thing.

Long answer: No, using the GMO option is the only viable way. You could do browse first / browse next until you found the msg id you wanted but that would make a database table scan look fast and efficient! It's the difference in database terms of using SELECT v using a cursor; with all the attendant programing issues. It also wouldn't scale well if at all & I urge you not to try it!

I'm still not clear on what you're trying to achieve... Why is the solution proposed by kevinf2349 not acceptable? Assuming this 2nd program is required for some reason I can't grasp?
_________________
Honesty is the best policy.
Insanity is the best defence.
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 » IBM MQ API Support » Trying to read multiple messages from 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.