Reputation: 2523
Javadoc for DefaultMessageListenerContainer says that
It is strongly recommended to either set "sessionTransacted" to "true" or specify an external "transactionManager".
Why is it strongly recommended? What's behind this cryptic recommendation?
Upvotes: 4
Views: 5734
Reputation: 933
If your session is not transacted you risk message loss in the event your JVM goes down unexpectedly.
Here is the explanation of the various ack modes from AbstractMessageListenerContainer:
The listener container offers the following message acknowledgment options:
"sessionAcknowledgeMode" set to "AUTO_ACKNOWLEDGE" (default): Automatic message acknowledgment before listener execution; no redelivery in case of exception thrown.
"sessionAcknowledgeMode" set to "CLIENT_ACKNOWLEDGE": Automatic message acknowledgment after successful listener execution; no redelivery in case of exception thrown.
"sessionAcknowledgeMode" set to "DUPS_OK_ACKNOWLEDGE": Lazy message acknowledgment during or after listener execution; potential redelivery in case of exception thrown.
"sessionTransacted" set to "true": Transactional acknowledgment after successful listener execution; guaranteed redelivery in case of exception thrown.
The exact behavior might vary according to the concrete listener container and JMS provider used.
Because messaging is typically based on assured delivery, using the method that would offer the best safegaurds against message loss is recommended. You'd have to decide for a particular use case if its worth it.
Upvotes: 5