When a client receives a message, the mandatory JMS-defined message property JMSXDeliveryCount will be set to the number of times the message has been delivered.
How to access:
in javax.jms.Message:
The purpose of the JMSXDeliveryCount property is to allow consuming applications to identify whether a particular message is being repeatedly redelivered and take appropriate action.
JMSXDeliveryCount property is not persisted, so not guaranteed to be exactly correct in server restart/failover. This property is also not propogated to backup server for high availability deployments. In case of server failure, if message is redelivered, it will be delivered with JMSXDeliveryCount as 2.
Following cases on client side are considered are redelivery attempts:
- MessageListener#onMessage() throwing RuntimeException: message will be redelivered with increased delivery count.
- in trasacted session and CLIENT_ACK mode: session.rollback() and queueReceiver.recover() will cause message to redelivered with increased delivery count.