Author |
Message
|
crayon_coco |
Posted: Wed Apr 13, 2005 8:49 pm Post subject: Get Message using matcahing message ID does not really works |
|
|
 Apprentice
Joined: 08 Oct 2003 Posts: 33
|
Hi
i have a method that will browse the message with the matching Message ID, it works find when i pass in a valid message id, when i pass in an array of 24 bytes with any value, it will still return me a message, how do i avoid the get to get message when i in this array without any value
below is my code, i have already set the get message option to MQC.MQMO_MATCH_MSG_ID
public void Browse(string queueName, byte[] messageID)
{
if(messageID != null)
{
queue = queueManager.AccessQueue (queueName,MQC.MQOO_BROWSE + MQC.MQOO_INQUIRE + MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_INPUT_SHARED);
MQGetMessageOptions queueGetMessageOptions = new MQGetMessageOptions();
queueGetMessageOptions.Options += MQC.MQGMO_BROWSE_FIRST + MQC.MQMO_MATCH_MSG_ID;
try
{
MQMessage queueMessage = new MQMessage();
queueMessage.MessageId = messageID;
queue.Get(queueMessage,queueGetMessageOptions);
this.message = queueMessage.ReadString queueMessage.MessageLength);
this.isExist = true;
this.isCompleted = true;
}
catch(MQException exp)
{
if(exp.Reason==MQC.MQRC_NO_MSG_AVAILABLE)
{
this.errorMessage = "Message Not Available";
this.isCompleted = true;
}
else
{
this.isCompleted = false;
throw new Exception(exp.ToString());
}
}
}
else
{
throw new Exception("MQ Message Data error : Null Message ID not allowed ");
}
} |
|
Back to top |
|
 |
mqmhr |
Posted: Wed Apr 13, 2005 10:06 pm Post subject: |
|
|
Centurion
Joined: 28 Dec 2004 Posts: 105
|
Crayon_Coco, if I think I understand your question correctly,
Change the if condition to (messageID!= null AND messageID != MQC.MQMI_NONE)
When the message id is not assigned any value before the Browse method call, the if condition will return false and so no message would be got from the queue. |
|
Back to top |
|
 |
crayon_coco |
Posted: Wed Apr 13, 2005 11:37 pm Post subject: |
|
|
 Apprentice
Joined: 08 Oct 2003 Posts: 33
|
HI,
i have tried it out but it didn't work.
i got the first message in the queue, what i want is if i pass in a array of bytes without values, it should not get the message at all,
i tried to do a loop the the array and convert it into string and i get a string of 0000000000000000000000000000000000000
Thanks
Coco |
|
Back to top |
|
 |
Nigelg |
Posted: Thu Apr 14, 2005 1:02 am Post subject: |
|
|
Grand Master
Joined: 02 Aug 2004 Posts: 1046
|
The string of all NULLs in the MsgId is MQC.MQMI_NONE, and matches all MsgId's, so your statement is wrong.
Quote: |
if i pass in a array of bytes without values, it should not get the message at all |
If you do this you will get any msg |
|
Back to top |
|
 |
Nigelg |
Posted: Thu Apr 14, 2005 1:03 am Post subject: |
|
|
Grand Master
Joined: 02 Aug 2004 Posts: 1046
|
BTW, try to avoid making the title of a post 'SOMETHING does not work', until you are sure that is is not your own fault. |
|
Back to top |
|
 |
woodoo2k |
Posted: Thu Apr 14, 2005 5:46 am Post subject: |
|
|
 Apprentice
Joined: 07 Feb 2005 Posts: 28 Location: USA
|
Hi Cryon_coco,
Try removing MQGMO_BROWSE_FIRST and then run your program.
It seems due to this options, MQSeries is fetching first message from the queue even when MSGID is not matched. |
|
Back to top |
|
 |
elvis_gn |
Posted: Thu Apr 21, 2005 8:58 pm Post subject: |
|
|
 Padawan
Joined: 08 Oct 2004 Posts: 1905 Location: Dubai
|
Hey,
For ur browse problem try something like this
status = 0;
if (status == 0) {
gmo.options = MQC.MQGMO_BROWSE_FIRST;
gmo.waitInterval = MQC.MQWI_UNLIMITED;
} else {
gmo.options = MQC.MQGMO_BROWSE_NEXT;
gmo.waitInterval = MQC.MQWI_UNLIMITED;
}
status = 1;
removeQueue.get(message, gmo);
This way u'll browse the first message first time and then always next.
About the messageId, i hope the problem is not that ur not fetching the messageId from the queue message properly....the messageId in the queue cannot be retrieved as a string...
It is a character array....
Give print statements first to see what are the messageId's ur comparing.. |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Apr 21, 2005 9:05 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
elvis_gn wrote: |
....
About the messageId, i hope the problem is not that ur not fetching the messageId from the queue message properly....the messageId in the queue cannot be retrieved as a string...
It is a character array....
Give print statements first to see what are the messageId's ur comparing.. |
Sorry but neither MessageId nor CorrelationID are a char array. They are byte arrays: byte[] !!
A char may limit the value, a byte does not.
Enjoy  |
|
Back to top |
|
 |
elvis_gn |
Posted: Thu Apr 21, 2005 9:40 pm Post subject: |
|
|
 Padawan
Joined: 08 Oct 2004 Posts: 1905 Location: Dubai
|
Sorry my mistake
Yes they are byte arrays |
|
Back to top |
|
 |
|