Example usage for org.springframework.amqp.core MessageProperties isRedelivered

List of usage examples for org.springframework.amqp.core MessageProperties isRedelivered

Introduction

In this page you can find the example usage for org.springframework.amqp.core MessageProperties isRedelivered.

Prototype

public Boolean isRedelivered() 

Source Link

Usage

From source file:org.springframework.amqp.rabbit.retry.MissingMessageIdAdvice.java

public Object invoke(MethodInvocation invocation) throws Throwable {
    String id = null;/*from ww w.j a  v a  2  s. co  m*/
    boolean redelivered = false;
    try {
        Message message = (Message) invocation.getArguments()[1];
        MessageProperties messageProperties = message.getMessageProperties();
        if (messageProperties.getMessageId() == null) {
            id = UUID.randomUUID().toString();
            messageProperties.setMessageId(id);
        }
        redelivered = messageProperties.isRedelivered();
        return invocation.proceed();
    } catch (Throwable t) {
        if (id != null && redelivered) {
            if (logger.isDebugEnabled()) {
                logger.debug("Canceling delivery of retried message that has no ID");
            }
            throw new ListenerExecutionFailedException("Cannot retry message without an ID",
                    new AmqpRejectAndDontRequeueException(t));
        } else {
            throw t;
        }
    } finally {
        if (id != null) {
            retryContextCache.remove(id);
        }
    }
}