首页 文章

避免向DLQ / DLX发送消息

提问于
浏览
1

我们的应用程序正在使用org.springframework.cloud,spring-cloud-starter-stream-rabbit框架,我们试图避免向DLQ发送特定消息并重试它们,这种行为应该以某种方式动态,因为对于默认消息,重试和DLQ应该工作 .

根据这个文件:

Putting it All Together

这个有用的帖子:

DLX in rabbitmq and spring-rabbitmq - some considerations of rejecting messages

似乎 ImmediateAcknowledgeAmqpException 可以在 Spring 季AMQP中用于将消息标记为已确认且无需进一步处理 . 但是,当我们使用此代码时:

@StreamListener(LogSink.INPUT)
public void handle(Message<Map<String, Object>> message) {

    if (message.getPayload().get("condition1").equals("abort")) {
        throw new ImmediateAcknowledgeAmqpException("error, we don't want to send this message to DLQ");
    }

    ...
}

消息始终发送到DLQ

我们目前的配置:

spring.cloud.stream:
  bindings:
    log:
      consumer.concurrency: 10
      destination: log
      group: myGroup
      content-type: application/json
  rabbit.bindings:
    log:
      consumer:
        autoBindDlq: true
        republishToDlq: true
        transacted: true

我们错过了什么吗?还有其他选择避免发布到DLQ并重新排队吗?

1 回答

  • 1

    republishToDlq 没有看那个例外;它仅在向容器抛出异常时应用(方法 causeChainHasImmediateAcknowledgeAmqpException() ) .

    重新发布颠覆了逻辑,因为没有异常被抛出到容器 .

    请打开针对Rabbit Binders 的问题, republishToDlq 应该尊重该异常并丢弃失败的消息 .

相关问题