簡體   English   中英

Spring 雲 Stream RabbitMQ 在死信隊列上留言

[英]Spring Cloud Stream RabbitMQ leave message on dead letter queue

我使用 Spring 雲流來使用來自 rabbitmq 的消息。 在多次重試后,我試圖讓失敗的消息留在死信隊列中。 在使用 amqp 之前,我已經以編程方式完成了此操作,但使用 spring 雲流似乎有點難以正確處理。

@StreamListener(target = Sink.INPUT)
public void messageListener(final String in, @Header(name = "x-death", required = false) Map<?, ?> death) {

  if (!validString(in)) {
    // We don’t need this message anymore not even on the dlq
    throw new ImmediateAcknowledgeAmqpException(“String not good”);
  }

  // If message has been retried more than 3 time we want to put message on dlq
  if (death != null && death.get("count").equals(3L)) {
    // I know this is incorrect as it will ack the message, but at this point I need the message to be left on the dlq
    throw new ImmediateAcknowledgeAmqpException("Failed after 4 attempts");
  }

  try {
    // this trows an exception
    processService.process(in);
  }
  catch (Exception ex) {
    // here we retry the message
    throw new AmqpRejectAndDontRequeueException("retry message");
  }
}

我的配置

spring.cloud.stream.bindings.input.destination=adestination
spring.cloud.stream.bindings.input.group=aqueue
spring.cloud.stream.rabbit.bindings.input.consumer.bindingRoutingKey=akey
#dlx/dlq setup
spring.cloud.stream.rabbit.bindings.input.consumer.deadLetterQueueName=adeadletterqueue
spring.cloud.stream.rabbit.bindings.input.consumer.dlqDeadLetterExchange=
spring.cloud.stream.rabbit.bindings.input.consumer.autoBindDlq=true
spring.cloud.stream.rabbit.bindings.input.consumer.requeueRejected=true
spring.cloud.stream.rabbit.bindings.input.consumer.dlqTtl=5000
# disable binder retries
spring.cloud.stream.bindings.input.consumer.max-attempts=1

非常感謝任何幫助

謝謝

您不能修改被拒絕的消息(例如添加 TTL 標頭)。

我相信當重試用盡時,您將不得不手動發布到停車場隊列。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM