|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
2 application getting message groups from a single queue |
« View previous topic :: View next topic » |
Author |
Message
|
JonB |
Posted: Fri Apr 13, 2012 4:22 am Post subject: 2 application getting message groups from a single queue |
|
|
 Apprentice
Joined: 14 Nov 2002 Posts: 27 Location: Dublin, Ireland
|
A question for all of the programming gurus!!!!
We are developing an application that will be run in two locations.
The queue manager resides on our z/OS platform, and the application will be run on a Linux platform, and connecting to the QMgr as an MQ client. Both application will be processing messages from tghe same queue, and all messages will be flagged as being part of a message group, even if the group only contains 1 message.
My question is, is it possible (hopefully not) for both applications to end up processing all or part of the same message group?
Common sense tells me that MQ will not allow this but just want to make sure! _________________ Jon Barry
IBM Certified System Administrator - WebSphere MQ V5.3
IBM Certified Solution Designer - WebSphere MQ V5.3 |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Apr 13, 2012 4:50 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
If you write your program to read messages off the queue completely ignoring any group indicators, then both instances of the program will receive messages from the queue as they arrive, in a random distribution.
i.e. if one message arrives while there are two outstanding GETs, it is random which GET will receive the message.
If you write your program to pay attention to group indicators, then you can ensure that both instances will not attempt to process the same group. For example: do a get without matching on GID, receive a message, keep getting matching on GID until you get the last message, then do another get without matching. |
|
Back to top |
|
 |
bruce2359 |
Posted: Fri Apr 13, 2012 4:55 am Post subject: |
|
|
 Poobah
Joined: 05 Jan 2008 Posts: 9469 Location: US: west coast, almost. Otherwise, enroute.
|
Yes, it's possible that multiple applications can consume messages from the same message group. There is nothing magic about a message group. It's all about how you write the application.
I suggest that you read the WMQ Application Programming Guide and WMQ Application Programming Reference for message groups.
In these (and the InfoCenter equivalents), you will discover that an application can match on GroupId (or not) to get messages only from a specific GroupId, or to get a message in _SYNCPOINT (or not). _________________ I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live. |
|
Back to top |
|
 |
JonB |
Posted: Tue Apr 17, 2012 3:13 am Post subject: |
|
|
 Apprentice
Joined: 14 Nov 2002 Posts: 27 Location: Dublin, Ireland
|
Super thanks for all of that.
We are going to have two instances of the same application running and processing the messages from the queue.
The application code currently is as follows:
Code: |
gmo = new MQGetMessageOptions();
gmo.options = CMQC.MQGMO_FAIL_IF_QUIESCING;
// wait for message to appear on queue
gmo.options = gmo.options + CMQC.MQGMO_WAIT;
// wait for a timeout for a message to appear
gmo.waitInterval = new Integer(props.getProperty("MQTimeout")).intValue();
// get next group only when all the messages are available and in the
// logical order sequence
gmo.options = gmo.options | CMQC.MQGMO_ALL_MSGS_AVAILABLE;
gmo.options = gmo.options | CMQC.MQGMO_LOGICAL_ORDER;
// match any message initially
gmo.matchOptions = MQConstants.MQMO_NONE;
Message nextMessage = null;
MQMessage mqMsg = null;
do {
mqMsg = new MQMessage();
mqRequestQueue.get(mqMsg, gmo);
gmo.matchOptions = CMQC.MQMO_MATCH_GROUP_ID;
if (mqMsg != null) {
nextMessage = new Message();
nextMessage.setReceivedTime(new Date());
nextMessage.setMessageId(mqMsg.messageId.toString());
byte[] payloadBytes = new byte[mqMsg.getMessageLength()];
mqMsg.readFully(payloadBytes);
nextMessage.setMQMessagePayload(payloadBytes);
nextMessage.setReturnQueueName(mqMsg.replyToQueueName);
nextMessage.setStatusRetrievedFromMQ();
nextMessage.setProcessing(false);
logger.finer("MQController>getNextMQMessage returning the " + gmo.groupStatus + " nextMessageId="
+ nextMessage.getMessageId() + " at " + nextMessage.getReceivedTime());
messages.add(nextMessage);
mqMsg.clearMessage();
// sleep to guarantee timestamp is unique - system specific, but
// as long as the timestamps are different thats all that
// matters
Thread.sleep(1);
}
// } while (gmo.groupStatus != CMQC.MQGS_LAST_MSG_IN_GROUP);
} while (gmo.groupStatus != MQ_LASTMESSAGE_IN_GROUP);
return messages; |
In it the initial get has no match options and then if the message is not the last message in the group it will redo a get using the Group ID in the match options.
Hopefully that will work for us. _________________ Jon Barry
IBM Certified System Administrator - WebSphere MQ V5.3
IBM Certified Solution Designer - WebSphere MQ V5.3 |
|
Back to top |
|
 |
zpat |
Posted: Tue Apr 17, 2012 3:54 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
I would suggest adding MQGMO_CONVERT in order to make it cross-platform compatible. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|