Is it possible for a consumer to look ahead at incoming messages? Is there anything for messages similar to the C library's getc() and ungetc() for character streams?

Jerry Smith

With point-to-point messaging, QueueBrowser supports look-ahead or primitive browsing operations without removing the message from the queue. QueueBrowser makes messages in the queue available via an Enumeration object. Note that the exact behavior, in terms of capturing the queue's current contents, will vary across JMS implementations.

For publish/subscribe messaging, the consumer can exercise limited control over the message queue with the Session.CLIENT_ACKNOWLEDGE acknowledgment mode:

  topicCon.createTopicSession(false, CLIENT_ACKNOWLEDGE);

In particular, messages remain available for re-processing until there is a client acknowledgment of a message; at this point the acknowledged message and all "older" messages become unavailable.