小编use*_*651的帖子

如何配置Spring AMQP在监听器抛出AmqpRejectAndDontRequeueException时不重新排队?

我目前有一个 Spring Boot 应用程序配置为使用 spring-boot-starter-amqp 2.1.5.RELEASE。我已在 yaml 中将其配置为重试:

  rabbitmq:
    listener:
      simple:
        retry:
          enabled: true # retrys enabled
          max-attempts: 3 # total number number attempts (includes the original one)
          multiplier: 1.5 # multiple of initial interval for subsequent retries
          initial-interval: 1000 # first interval between attempts
Run Code Online (Sandbox Code Playgroud)

在我的监听器中,在某种情况下,我抛出 AmqpRejectAndDontRequeueException 但这并不能阻止重新排队。

如果抛出此异常,如何配置与自动 spring 配置内联的配置 bean 以停止进一步重新排队消息?

队列 A 应尝试对队列A 侦听器进行处理 3 次,并且日志支持这一点。队列 B 应该只尝试一次,并在抛出 AmqpRejectAndDontRequeueException 时停止。

SpringBoot应用程序类:

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.List;

import javax.annotation.PostConstruct;

import org.apache.commons.lang3.ObjectUtils;
import org.springframework.amqp.AmqpRejectAndDontRequeueException;
import org.springframework.amqp.core.AmqpAdmin; …
Run Code Online (Sandbox Code Playgroud)

spring-rabbit spring-amqp spring-retry

2
推荐指数
1
解决办法
6550
查看次数

标签 统计

spring-amqp ×1

spring-rabbit ×1

spring-retry ×1