Author |
Message
|
chornbe |
Posted: Thu Aug 31, 2006 9:41 am Post subject: Just want to scan a queue for a particular message - .NET/C# |
|
|
Newbie
Joined: 31 Aug 2006 Posts: 3
|
So, I have a multi-use queue - I can't apparently get a dedicated queue - don't ask.
I want to just scan the queue and look for messages that I care about.
Working with test code (this is *not* production quality code), I assumed I need to start at the beginning of queue, and browse until I find what I need, get message under cursor and move on with my life.
However, it appears in the following code the cursor never really moves to the next message, or that I'm starting at the *end* of the queue. I get a message, however when moving to the next message, I get "no message available" (RC 2033) errors.
Am I missing something? A nice, simple ".Peek()" function would have been real cool!
Code snippet follows:
Code: |
try {
bool found = false;
gmo = new MQGetMessageOptions();
gmo.Options = MQC.MQGMO_ALL_MSGS_AVAILABLE + MQC.MQGMO_BROWSE_FIRST;
while( !found ){
queue.Get( queueMessage, gmo );
gmo.Options = MQC.MQGMO_ALL_MSGS_AVAILABLE + MQC.MQGMO_BROWSE_NEXT;
Console.WriteLine( queueMessage.ReadString( queueMessage.MessageLength) );
// select message and set found=true...
}
} catch (MQException MQExp) {
// report the error
System.Console.WriteLine( "MQQueue::Get ended with " + MQExp.Message +
MQExp.Reason + MQExp.ReasonCode + MQExp.Source );
}
|
Thanks! |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Aug 31, 2006 9:51 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
You need to reset the MQMD MsgId and CorrelId after each get. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Aug 31, 2006 9:52 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
You need to reset the MQMD MsgId and CorrelId after each get. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
chornbe |
Posted: Thu Aug 31, 2006 10:01 am Post subject: |
|
|
Newbie
Joined: 31 Aug 2006 Posts: 3
|
uh... forgive my ignorance. How? (I'm used to writing for MSMQ, so bear with me ) |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Aug 31, 2006 10:04 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
I dunno how to do it in .NET - maybe just make a new queueMessage every time through. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
wschutz |
Posted: Thu Aug 31, 2006 10:07 am Post subject: |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
Why not just add MQC.MQMO_NONE to the gmo.MatchOptions? _________________ -wayne
Last edited by wschutz on Thu Aug 31, 2006 10:26 am; edited 1 time in total |
|
Back to top |
|
 |
chornbe |
Posted: Thu Aug 31, 2006 10:15 am Post subject: |
|
|
Newbie
Joined: 31 Aug 2006 Posts: 3
|
jefflowrey wrote: |
I dunno how to do it in .NET - maybe just make a new queueMessage every time through. |
Bingo! Thanks much. That did it. Here's what worked:
Code: |
try {
bool found = false;
gmo.Options = MQC.MQGMO_ALL_MSGS_AVAILABLE + MQC.MQGMO_BROWSE_FIRST;
gmo.MatchOptions = MQC.MQMO_MATCH_CORREL_ID + MQC.MQMO_MATCH_MSG_ID;
while( !found ){
queue.Get( queueMessage, gmo );
Console.WriteLine( queueMessage.ReadString( queueMessage.MessageLength) );
queueMessage = new MQMessage();
queueMessage.Format = MQC.MQFMT_STRING;
gmo = new MQGetMessageOptions();
gmo.Options = MQC.MQGMO_ALL_MSGS_AVAILABLE + MQC.MQGMO_BROWSE_NEXT;
// select message and set found=true...
}
} catch (MQException MQExp) {
// report the error
System.Console.WriteLine( "MQQueue::Get ended with " + MQExp.Message +
MQExp.Reason + MQExp.ReasonCode + MQExp.Source );
}
|
Thank you! |
|
Back to top |
|
 |
tleichen |
Posted: Thu Aug 31, 2006 10:44 am Post subject: Re: Just want to scan a queue for a particular message - .NE |
|
|
Yatiri
Joined: 11 Apr 2005 Posts: 663 Location: Center of the USA
|
chornbe wrote: |
So, I have a multi-use queue - I can't apparently get a dedicated queue - don't ask.
|
I'm asking anyway.... why are you (or someone else) trying to complicate the problem by going against the grain with how this product was designed to function? That is the question you should be confronting your administrators and your management with whenever they try pushing you into sharing queues between various applications. The added programming and potential problems involved with sharing a queue between various applications is simply not worth it! (IMHO)
btw, is this a client or server app, and what platform is the queue manager on?  _________________ IBM Certified MQSeries Specialist
IBM Certified MQSeries Developer |
|
Back to top |
|
 |
Vitor |
Posted: Fri Sep 01, 2006 4:13 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
If you're trying to loop through a queue, you'll find it faster & more resource efficient to use wschutz suggestion of replacing MQC.MQMO_MATCH etc with MQC.MQMO_NONE. This will allow you to reuse the same Message object by preventing matching.
But if it works and you're happy (and resource isn't a consideration) leave it!
(It is better to have a dedicated queue though. Saves a fortune in resource because apps don't have to do all this "hunt the message" stuff, amongst other benefits. Challenge the decision & demand your own queue - you deserve it!)  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
|