Skip to content

Async @RabbitListener does not handle AmqpRejectAndDontRequeueException #1058

Closed
@peterlgh7

Description

@peterlgh7

Bug report

spring-amqp version: 2.1.7-RELEASE

The documentation for asynchronous @RabbitListener states:

If the async result is completed with an AmqpRejectAndDontRequeueException, the message will not be requeued.

The following example listener instead requeues the message and loops indefinitely:

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.SettableListenableFuture;

@Component
public class Listener {

  @RabbitListener(queues = "example")
  public ListenableFuture<Void> receive(User user) {
    System.out.println(user);
    SettableListenableFuture<Void> future = new SettableListenableFuture<>();
    future.setException(new RuntimeException());
    return future;
  }
}

The problem seems to lie on the AbstractAdaptableMessageListener. The requeue flag is true regardless of the exception type:

private void asyncFailure(Message request, Channel channel, Throwable t) {
this.logger.error("Future or Mono was completed with an exception for " + request, t);
try {
channel.basicNack(request.getMessageProperties().getDeliveryTag(), false, true);
}
catch (IOException e) {
this.logger.error("Failed to nack message", e);
}
}

Moreover, not an issue for me now, but the documentation also states:

By default, the message will be requeued, unless the container’s defaultRequeueRejected property is set to false

And from the snippet above, it doesn't seem to be true either.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions