📝

[小ネタ] SQS では配信済みと記録されたメッセージを受信できないケースがある

に公開

Avoiding inconsistent message processing in Amazon SQS - Amazon Simple Queue Service

Because Amazon SQS is a distributed system, it is possible for a consumer to not receive a message even when Amazon SQS marks the message as delivered while returning successfully from a ReceiveMessage API method call. In this case, Amazon SQS records the message as delivered at least once, although the consumer has never received it. Because no additional attempts to deliver messages are made under these conditions, we don't recommend setting the number of maximum receives to 1 for a dead-letter queue.

ReceiveMessage API 実行後に SQS がメッセージを配信済みにマークしても、コンシューマーはメッセージを受信しないことがあるという仕様です。

対策

上述の通りデッドレターキューの最大受信数を 1 にせず、デッドレターキューに送信されるまでにメッセージを受信できる回数を増やすことが対策となります。

Configure a dead-letter queue using the Amazon SQS console - Amazon Simple Queue Service

Set the Maximum receives value, which defines how many times a message can be received before being sent to the dead-letter queue (valid range: 1 to 1,000).

最大受信数が 1 の場合にコンシューマーが受信できなかったメッセージはデッドレターキューに送信されます。

まとめ

今回は SQS では配信済みと記録されたメッセージを受信できないケースがあるという内容を紹介しました。
どなたかの参考になれば幸いです。

参考資料

Discussion