ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » How to read the latest message from queue manager

Post new topic  Reply to topic
 How to read the latest message from queue manager « View previous topic :: View next topic » 
Author Message
pras120687
PostPosted: Wed Jan 26, 2022 4:08 am    Post subject: How to read the latest message from queue manager Reply with quote

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
View user's profile Send private message
hughson
PostPosted: Thu Jan 27, 2022 1:56 am    Post subject: Reply with quote

Padawan

Joined: 09 May 2013
Posts: 1914
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
View user's profile Send private message Visit poster's website
zpat
PostPosted: Thu Jan 27, 2022 5:11 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » How to read the latest message from queue manager
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.