• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

AUTO_ACK for JMS P2P

 
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 =
queueConnectionFactory.createQueueConnection();
queueSession =
queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
queueReceiver = queueSession.createReceiver(queue);
queueConnection.start();
while (true) {
Message m = queueReceiver.receive(1);
if (m != null) {
if (m instanceof TextMessage) {
message = (TextMessage) m;
System.out.println("Reading message: " +
message.getText());
} else {
break;
}
}
}
} catch (JMSException e) {
System.out.println("Exception occurred: " +
e.toString());
}
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Regards.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sam,

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

http://www.javaworld.com/javaworld/jw-03-2002/jw-0315-jms_p.html

Mohana
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic