St.Antario
St.Antario

Reputation: 27385

Acknowledgment mode for transacted producer's session

ActiveMQ 5.7.0/ JMS 1.1

I have one question about acknowledgment modes. I'm creating a session for a producer as follows:

ConnectionFactory connectionFactory;
Queue testQueue
//init connectionFactory, testQueue
Connection c = connectionFactory.createConnection();
c.start();
Session s = c.createSession(true, Session.AUTO_ACKNOWLEDGE); // <----- What does it mean?
MessageProducer mp = s.createProducer(testQueue);
mp.setDeliveryMode(DeliveryMode.PERSISTENT);
//sending messages

As to the official documentation:

In auto-acknowledge mode, the Message Queue client runtime immediately sends a client acknowledgment for each message it delivers to the message consumer

So the acknowledgment modes are about delivering messages to producers. What should I specify there if I'm going to use the session for only sending messages? Maybe I should specify the Session.SESSION_TRANSACTED mode? But I didn't see the specification for the mode in the official documentation I cited. Is that a vendor-specific?

Upvotes: 0

Views: 569

Answers (1)

Tim Bish
Tim Bish

Reputation: 18366

Actually the Session.SESSION_TRANSACTED is right in the API docs for JMS Session. Although generally it doesn't matter what you put into the acknowledgement mode value when you create a transacted session since the provider will usually override that, but it's good form to use the transacted value.

As far as how the acknowledgement mode affects message producers, it doesn't, short and sweet. In a transacted session the messages you produce are not posted to the target destination by the remote peer until you commit, if you rollback they are lost (possibly DLQ'd). A producer has no mechanism to ack messages so nothing to worry about.

Upvotes: 1

Related Questions