【发布时间】:2021-10-28 18:42:53
【问题描述】:
当订阅 http-endpoint 返回客户端错误时,Amazon SNS 不会向死信队列 (DLQ) 发送消息。
我有一个向 https 端点发送通知的 SNS 主题。我还为其附加了一个死信队列并启用了传递状态记录。
当通知由于网络超时或来自端点的服务器端错误(例如 500)而无法到达端点时,通知进入重试策略并在配置的重试次数后发送通知到DLQ。这很好用!日志如下所示:
{
"notification": {
"messageMD5Sum": "1234",
"messageId": "123-456-789",
"topicArn": "arn:aws:sns:eu-west-1:1234:mysnstopic",
"timestamp": "2021-06-08 15:15:21.454"
},
"delivery": {
"deliveryId": "84b16cc6-09bd-5186-a6cb-35ff8274dc9d",
"redrivePolicy": "{\n \"deadLetterTargetArn\": \"arn:aws:sqs:eu-west-1:1234:mydlq\"\n}\n",
"destination": "https://my-endpoint.xy/",
"providerResponse": "Socket timeout in HttpClient",
"dwellTimeMs": 30137,
"attempts": 3
},
"status": "FAILURE"
}
但有时会发生,https 端点以客户端错误(例如 404)响应。在这种情况下,SNS 将通知记录为“SUCCESS”并完成。它不会进入重试策略(可以),也不会向 DLQ 发送通知(不可以)。日志如下所示:
{
"notification": {
"messageMD5Sum": "1234",
"messageId": "123-456-789",
"topicArn": "arn:aws:sns:eu-west-1:1234:mysnstopic",
"timestamp": "2021-06-08 15:24:46.146"
},
"delivery": {
"deliveryId": "111-222-333",
"redrivePolicy": "{\n \"deadLetterTargetArn\": \"arn:aws:sqs:eu-west-1:1234:mydlq\"\n}\n",
"destination": "https://my-endpoint.xy/",
"providerResponse": "Not Found",
"dwellTimeMs": 202,
"attempts": 1,
"statusCode": 404
},
"status": "SUCCESS"
}
在documentation 它说
通常,当 Amazon SNS 由于客户端或服务器端错误而无法访问订阅的终端节点时,消息传递会失败。当 Amazon SNS 收到客户端错误,或继续收到超出相应重试策略指定的重试次数的消息的服务器端错误时,Amazon SNS 会丢弃该消息 — 除非死信队列附加到订阅。
根据文档,我希望收到 404 的通知不是成功而是失败,并被发送到 DLQ。如何配置它以获得预期的效果?
【问题讨论】:
标签: amazon-web-services amazon-sns