Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JMS - how to remove a message from Queue

 
Naveen Sampra
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Naveen Sampra
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic