File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes AUTO_ACK for JMS P2P Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "AUTO_ACK for JMS P2P" Watch "AUTO_ACK for JMS P2P" New topic


Sam Gehouse
Ranch Hand

Joined: Jul 21, 2003
Posts: 281
I am looking at some sample code for JMS for simple P2P.

If I use AUTO_ACKNOWLEDGE, does my program automatically listen whenever a message is put into the queue? If I use AUTO_ACKNOWLEDGE, do I not need any listener to listen every time a message is put into the queue?

I am providing some sample code below:

try {
queueConnection =
queueSession =
queueReceiver = queueSession.createReceiver(queue);
while (true) {
Message m = queueReceiver.receive(1);
if (m != null) {
if (m instanceof TextMessage) {
message = (TextMessage) m;
System.out.println("Reading message: " +
} else {
} catch (JMSException e) {
System.out.println("Exception occurred: " +
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Sam,

Actually the meaning of message acknowledgement is little bit different. Basically when a jms message consumer finishes processing a message it needs to notify the jms provider that the message could be removed. The AUTO_ACKNOWLEDGE flag says that the messages are automatically acknowledged one by one after consumption. This is the easiest form of message acknowledgement but it is the most inefficient one as well, because it acknowledges only one message at a time. You might use other message acknowledgement types, including DUPS_ ACKNOWLEDGE (this is kind of lazy acknowledgement, which is very efficient) or CLIENT_ ACKNOWLEDGE (whicih is the opposite: the client will manually acknowledge the jms provider). They could also be other vendor specific flags, like MULTICAST_NO_ACKNOWLEDGE which invokes multicasting, etc.

I think, therefore I exist -- Rene Descartes
Mohana Murali

Joined: Sep 26, 2002
Posts: 27

here is good article on it. May be in will help more on understanding JMS transactions and acknowledgements.

I agree. Here's the link:
subject: AUTO_ACK for JMS P2P
It's not a secret anymore!