当 subscription-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 将通知记录为“成功”并完成。它不会进入重试策略(正常),也不会向 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。如何配置才能达到预期效果?