Author |
Message
|
crayon_coco |
Posted: Mon Mar 14, 2005 2:32 am Post subject: How to browse a message using MessageID |
|
|
 Apprentice
Joined: 08 Oct 2003 Posts: 33
|
If i have the Message ID how do i browse to get the correct the message from the queue with the message ID without removing it from the queue |
|
Back to top |
|
 |
bower5932 |
Posted: Mon Mar 14, 2005 7:25 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
You specify on the MQGMO.options that you want to browse the message. Look in the Application Programming Reference for:
MQGMO_BROWSE_FIRST
MQGMO_BROWSE_NEXT
You'll also find information on locking (MQGMO_LOCK). |
|
Back to top |
|
 |
crayon_coco |
Posted: Mon Mar 14, 2005 4:55 pm Post subject: |
|
|
 Apprentice
Joined: 08 Oct 2003 Posts: 33
|
So does it mean that i have to loop through the queue and find the message that i want? how do i do it with the MessageID that i have? |
|
Back to top |
|
 |
bob_buxton |
Posted: Tue Mar 15, 2005 1:28 am Post subject: |
|
|
 Master
Joined: 23 Aug 2001 Posts: 266 Location: England
|
You set the messageid you want in the MQMD prior to issuing your browse first call and it will return the first message with that id. Subsequent browse next calls could be used to return any messages with duplicate message ids. _________________ Bob Buxton
Ex-Websphere MQ Development |
|
Back to top |
|
 |
crayon_coco |
Posted: Tue Mar 15, 2005 1:55 am Post subject: |
|
|
 Apprentice
Joined: 08 Oct 2003 Posts: 33
|
i tried that and i works for the Message that is in the queue, when i set the MQMD to a messageid that is not exist in the queue it will just return any message that is in the last in the queue |
|
Back to top |
|
 |
bower5932 |
Posted: Tue Mar 15, 2005 7:18 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
Check out the matching options. There is an option that indicates you want to match based on message id.
Code: |
#define MQMO_MATCH_MSG_ID 0x00000001
#define MQMO_MATCH_CORREL_ID 0x00000002
#define MQMO_MATCH_GROUP_ID 0x00000004
#define MQMO_MATCH_MSG_SEQ_NUMBER 0x00000008
#define MQMO_MATCH_OFFSET 0x00000010
#define MQMO_MATCH_MSG_TOKEN 0x00000020 |
|
|
Back to top |
|
 |
malammik |
Posted: Tue Mar 15, 2005 8:31 am Post subject: |
|
|
 Partisan
Joined: 27 Jan 2005 Posts: 397 Location: Philadelphia, PA
|
Here is a sample you can modify to return base MQMessage class.
public QFlexMessage browseMessageById(String queueName, byte[] messageId) {
int openOptions = MQC.MQOO_FAIL_IF_QUIESCING | MQC.MQOO_BROWSE | MQC.MQOO_INQUIRE;
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_BROWSE_NEXT | MQC.MQGMO_FAIL_IF_QUIESCING;
// Set message id.
MQMessage msg = new MQMessage();
msg.messageId = messageId;
MQQueue queue = null;
MQQueueManager qmConnection = null;
QFlexMessage qmessage = null;
try {
qmConnection = MqPcfUtil.getMQQueueManagerConnection(qmanager);
queue = qmConnection.accessQueue(queueName, openOptions);
// Obtain a message by id.
queue.get(msg, gmo);
qmessage = new QFlexMessage(msg);
}
catch (MQException e) {
if (e.reasonCode == MQException.MQRC_NO_MSG_AVAILABLE) {
logger.info("message is no longer on the queue");
}
else {
logger.error("Failed to access queue :" + queueName, e);
}
}
finally {
try {
if (queue != null && queue.isOpen()) {
queue.close();
}
}
catch (MQException mqe) {
logger.error(mqe);
}
try {
if (qmConnection != null && qmConnection.isOpen()) {
qmConnection.disconnect();
}
}
catch (MQException mqe) {
logger.error(mqe);
}
}
return qmessage;
} _________________ Mikhail Malamud
http://www.netflexity.com
http://groups.google.com/group/qflex |
|
Back to top |
|
 |
|