• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

JMS - how to remove a message from Queue

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic