简体   繁体   English

处理 AWS SQS 死信队列

[英]Handle AWS SQS Dead Letter Queue

I've configured a DLQ in AWS following this article: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-configure-dead-letter-queue.html我已经按照这篇文章在 AWS 中配置了一个 DLQ: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-configure-dead-letter-queue.html

This is the consumer I have in a sprint boot application:这是我在 sprint 启动应用程序中的消费者:

@SqsListener(value = "${cloud.aws.endpoint.queue-name}", deletionPolicy = SqsMessageDeletionPolicy.DEFAULT)
private void getMessage(final Event event) {
    // process event
}

However, when there is an exception during the event processing, say a NPE, an exception calling an external REST API etc, the messages that failed to be processed are not flowing into the dead letter queue.但是,当事件处理过程中出现异常,比如NPE,异常调用外部REST API等,处理失败的消息不会流入死信队列。

Am I missing anything?我错过了什么吗?

It's difficult to help with the few info you provide but check the following:您提供的信息很少,很难提供帮助,但请检查以下内容:

Perhaps your queue is not properly setup也许您的队列设置不正确

Dead letter queues redirection are not related to the consumer setup but to the way that the queues have been configured at creation in aws.死信队列重定向与消费者设置无关,而是与在 aws 中创建队列时配置的方式有关。 So use the aws cli get-queue-attributes command https://docs.aws.amazon.com/cli/latest/reference/sqs/get-queue-attributes.html to check if your source queue has the proper RedrivePolicy .因此,请使用 aws cli get-queue-attributes命令https://docs.aws.amazon.com/cli/latest/reference/sqs/get-queue-attributes.html检查您的源队列是否具有正确的RedrivePolicy The output should display something like this example . output 应该显示类似于此示例的内容。 Also controls that the maxReceiveCount is setup properly in your source queue.还控制maxReceiveCount在源队列中是否正确设置。 From the doc:从文档:

maxReceiveCount – The number of times a message is delivered
to the source queue before being moved to the dead-letter queue.
When the ReceiveCount for a message exceeds the maxReceiveCount for a queue,
Amazon SQS moves the message to the dead-letter-queue.

If the dead letter queue has not been configured properly follow the aws create-queue https://docs.aws.amazon.com/cli/latest/reference/sqs/create-queue.html cli example to setup a dead letter queue to the source queue.如果死信队列未正确配置,请按照 aws create-queue https://docs.aws.amazon.com/cli/latest/reference/sqs/create-queue.html cli 示例设置死信队列以源队列。

Try to send a message to the queue outside of spring using cli only with send-message https://docs.aws.amazon.com/cli/latest/reference/sqs/send-message.html and ensure that the dead letter queue is properly popolated.尝试仅使用带有send-message https://docs.aws.amazon.com/cli/latest/reference/sqs/send-message.html的 cli 将消息发送到 spring 之外的队列,并确保死信队列被正确填充。

Perhaps SqsListener is not pointing to the correct source queue可能SqsListener没有指向正确的源队列

Messages may not be reaching the correct source queue that has a dead-letter queue attached.消息可能没有到达附加了死信队列的正确源队列。 cloud.aws.endpoint.queue-name should be the path to find the queue name in your application properties application.yml like you just defined it: cloud.aws.endpoint.queue-name应该是在您的应用程序属性application.yml中查找队列名称的路径,就像您刚刚定义的那样:

cloud:
 aws:
  endpoint:
   queue-name: "my-queue-name"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Boto3创建SQS队列时指定死信队列 - Specify a dead letter queue when creating an SQS queue using Boto3 如何为使用 Terraform 生成的 SQS 队列获取死信队列的 URL? - How to get the URL for a Dead Letter Queue for an SQS queue generated using Terraform? 配置 SQS 死信队列以在收到消息时发出云监视警报 - Configure SQS Dead letter Queue to raise a cloud watch alarm on receiving a message 事件源映射(对于 AWS MSK-Lambda)是否将消息发送到 aws lambda 中的死信队列? - Does Event Source Mapping (For AWS MSK-Lambda) send messages to dead letter queue in aws lambda? SNS 重新驱动到死信队列不起作用 - SNS redrive to Dead letter queue not working Laravel 中与 AWS Sqs 队列相关的错误 - Error related to AWS Sqs Queue in Laravel Azure函数中的Service Bus死信队列处理 - Service Bus Dead Letter Queue Processing In Azure Functions 从 AWS SQS 队列中缓慢删除消息 - Slow deleting message from AWS SQS queue 无法为多个环境创建 aws sqs 队列? - Could not create aws sqs queue for multiple environment? 代码没有错误,为什么消息仍然被发送到死信队列? - No bugs in codes, why messages are still being sent to Dead Letter Queue?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM