Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes EJB and other Java EE Technologies and the fly likes JMS - how to remove a message from Queue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JMS - how to remove a message from Queue" Watch "JMS - how to remove a message from Queue" New topic
Author

JMS - how to remove a message from Queue

Naveen Sampra
Ranch Hand

Joined: Jun 11, 2003
Posts: 70
Hi All,

How do I read existing messages on the Queue(not new ones that arrive). Say that messages arrive on a queue and NO listeners are defined. So the messages get queued up.

I want to programatically read the first message on the queue.

Say "receiver" is of QueueReceiver type and initialized correctly to reference the queue I'm reading.

All of the following do NOT read the message in the queue. I think they only read new messages that arrive.

Message msg = receiver.receiveNoWait();
OR
Message msg = receiver.receive(1000);

Results in msg == null. That is no message is read.

Any idea how to retrieve an existing message from a JMS Queue.

Thanks.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


All of the following do NOT read the message in the queue. I think they only read new messages that arrive

No. All messages on the Queue will be processed - though not necessarily by this QueueReceiver if more than one is defined from this Queue. Messages can be skipped if the QueueReceiver specifies a message selector.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Naveen Sampra
Ranch Hand

Joined: Jun 11, 2003
Posts: 70

All messages on the Queue will be processed


If this is true I wonder why my Message msg = receiver.receiveNoWait(); is returning null.

1) I do have a MDB which is configured to listen on this queue. However I stopped the listener service on the server that the MDB is deployed on when I ran the above mentioned test code to read the first message off the queue.

2) When creating the queue I did not specify any message selector, which means I should be able to read ALL messages on the queue.

3) Using QueueBrowser qBrowser = qSession.createBrowser(q, null); I can browse the queue and I do see that there are 2 messages. i.e Using qBrowser.getEnumeration() I can see two Message objects in the queue.

Why is it my failing ?

Would appreciate any help ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JMS - how to remove a message from Queue
 
Similar Threads
Revoking an already sent JMS Message
how to send the message to Queue
JMS question
read all messages from queue
JMS on JBOSS- Asynchronous Queue Receiver