[英]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:您提供的信息很少,很难提供帮助,但请检查以下内容:
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 之外的队列,并确保死信队列被正确填充。
SqsListener
is not pointing to the correct source queueSqsListener
没有指向正确的源队列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.