|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
![Reply to topic](templates/DAJ_Glass/images/lang_english/reply.gif) |
|
How to read the latest message from queue manager |
« View previous topic :: View next topic » |
Author |
Message
|
pras120687 |
Posted: Wed Jan 26, 2022 4:08 am Post subject: How to read the latest message from queue manager |
|
|
Newbie
Joined: 06 Jan 2022 Posts: 6
|
Hi,
I have code to read the message from queue manager. But I am reading the message which is not latest. Can you guide me how to read the latest message from queue manager. Please find the below code for reference
Code: |
qMgr = new MQQueueManager(this.queueManagerReceiver);
int openOptions = MQConstants.MQOO_INPUT_EXCLUSIVE | MQConstants.MQOO_BROWSE;
MQQueue queue1 = qMgr.accessQueue(queueNameReceiver, openOptions);
MQMessage readMessage = new MQMessage();
MQGetMessageOptions gmo =new MQGetMessageOptions();
gmo.options=MQConstants.MQOO_INQUIRE|MQConstants.MQGMO_WAIT|MQConstants.MQGMO_CONVERT;
gmo.waitInterval=6000;
queue1.get(readMessage,gmo);
gmo.groupStatus = MQConstants.MQGS_NOT_IN_GROUP;
gmo.matchOptions = MQConstants.MQMO_NONE;
int lengthOfMsg =readMessage.getTotalMessageLength();
System.out.println("Length is: "+lengthOfMsg);
msgText = readMessage.readStringOfByteLength(lengthOfMsg);
System.out.println("Received message is second "+msgText); |
|
|
Back to top |
|
![](templates/DAJ_Glass/images/spacer.gif) |
hughson |
Posted: Thu Jan 27, 2022 1:56 am Post subject: |
|
|
![](images/avatars/810794940518bb946528b3.jpg) Padawan
Joined: 09 May 2013 Posts: 1916 Location: Bay of Plenty, New Zealand
|
The way a queue in IBM MQ is created by default will make it a First In First Out (FIFO) queue, so if you read from the queue you will be given the first message that arrived on the queue, not the most recent message.
If you don't want a FIFO queue, your alternative is to have a Priority ordered queue, where you will be given the highest priority message rather than the first message that arrived on the queue. This allows high priority messages to "jump ahead" of other messages and is how some applications wish to operate.
There is no option for a Last In First Out (LIFO) queue in IBM MQ, which is what it sounds like you are asking for?
Perhaps you can tell us the reason why you want to read the latest message from on the queue. There might be a better way than just browsing every message until there are no more messages, which would be how you would get to the most recent message.
Cheers,
Morag _________________ Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software |
|
Back to top |
|
![](templates/DAJ_Glass/images/spacer.gif) |
zpat |
Posted: Thu Jan 27, 2022 5:11 am Post subject: |
|
|
![](images/avatars/200698233754e3c3649f6d0.jpg) Jedi Council
Joined: 19 May 2001 Posts: 5849 Location: UK
|
Maybe a case for pub/sub and retained publications.
Why open a queue for browse if you want to consume a message?
(or)
Why open a queue for input if you want to browse a message? _________________ Well, I don't think there is any question about it. It can only be attributable to human error. This sort of thing has cropped up before, and it has always been due to human error. |
|
Back to top |
|
![](templates/DAJ_Glass/images/spacer.gif) |
|
|
![Reply to topic](templates/DAJ_Glass/images/lang_english/reply.gif) |
|
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
|
|
|
|