Processing redelivery of AMQP messages

Spring AMQP SimpleMessageListenerContainer (SMLC) is session transacted,  it has a AckMode field whose default value is AUTO. AUTO Acknowledge ensures that if a message processing fails with an exception then it sends NACK and requeues the message back to queue. Your application may need to handle the retry logic, you just cant let a message fail forever (unless you have a requirement to not lose any message).

Here is how you can handle it
  Create a MessageListener class implementing the interface org.springframework.amqp.core.MessageListener.
In its onMessage  check the basic property
   boolean isRedelivered = amqpMessage.getMessageProperties().getRedelivered();

   You can get the redelivery count from deliveryTag
     long deliveryTag = amqpMessage.getMessageProperties().getDeliveryTag();

 Now write your logic
   if(deliveryTag >= maxRedeliveryCount) {
       //Store the message in file system or database
       //do not throw the exception
  }

Comments

Popular posts from this blog

NSSM service eats 100% CPU

JPA Vs SpringJDBC

Ignite Running in Static IP multicast mode