Direkt zum Inhalt

SQS FIFO SendMessageBatch: Are subsequent messages enqueued when a previous message fails?

0

When using SendMessageBatch with an SQS FIFO queue, what happens if a message in the middle of the batch fails?

Scenario

I send a batch of 3 messages (A, B, C) with the same MessageGroupId to a FIFO queue using SendMessageBatch. Message B fails due to an internal SQS error (not a client-side validation error), but messages A and C would otherwise succeed.

Question:

  1. Are messages A and C enqueued in the FIFO queue?
  2. If yes, does message C get enqueued even though message B (which came before it) failed?

Code Example

// Batch: [Message A, Message B, Message C] - same MessageGroupId
SendMessageBatchResponse response = sqsClient.sendMessageBatch(request);

// Is it even possible for response to show: A=success, B=failed, C=success?
// If yes, what's actually in the queue?

The AWS documentation states "For a FIFO queue, multiple messages within a single batch are enqueued in the order they are sent" but doesn't clarify the behavior when some messages in the batch fail.

gefragt vor einem Jahr297 Aufrufe

1 Antwort
0

When using SendMessageBatch with an SQS FIFO queue, the success or failure of individual messages within the batch is handled independently. This means that in your scenario:

  1. Yes, messages A and C would be enqueued in the FIFO queue if they succeed, even if message B fails.
  2. Yes, message C would still be enqueued even though message B (which came before it) failed.

The batch request can result in a combination of successful and unsuccessful actions, which is why you should check for batch errors even when the call returns an HTTP status code of 200. Each message's result is reported individually in the response.

For a FIFO queue, messages within a single batch are enqueued in the order they are sent, but this applies only to the messages that successfully make it to the queue. If message B fails due to an internal SQS error, it simply won't be part of the queue, while messages A and C will be enqueued in their respective order (A followed by C).

It's important to note that this behavior is different from message processing behavior. When processing messages from a FIFO queue (for example, with Lambda), messages with the same message group ID are processed in strict order, and only one message from each group is processed at a time to maintain this sequential order. But this ordering guarantee applies only to messages that have successfully been enqueued in the first place.

So in your code example, it is indeed possible for the response to show A=success, B=failed, C=success, and in that case, only messages A and C would be in the queue (in that order).
Sources
SendMessageBatch - Amazon Simple Queue Service
SqsAsyncClient (AWS SDK for Java - 2.21.29)
Amazon SQS FIFO queue and Lambda concurrency behavior - Amazon Simple Queue Service

beantwortet vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.