Skip to content

SQS behavior for change-message-visibility vs change-message-visibility-batch

0

I am using AWS JAVA SDK (v1) for testing SQS APIs. Below is the behavior if receipt handle is expired (corresponding message is deleted). changeMessageVisibility:

Error changing message visibility: Value AAA for parameter ReceiptHandle is invalid. Reason: The receipt handle has expired. 
(Service: AmazonSQS; Status Code: 400; Error Code: InvalidParameterValue; Request ID: RRR; Proxy: null)

changeMessageVisibilityBatch:

{Id: a,
SenderFault: true,
Code: ReceiptHandleIsInvalid,
Message: The receipt handle has expired}

In above response:

  • Why is error code different (InvalidParameterValue for one but ReceiptHandleIsInvalid for other) ? Is the error code expected to be different for both ? I believed it should be same for both since both are changing message visibility timeout (single or in batch). Since the receipt handle was valid (in the past) but expired now (message is deleted), what should be correct error code for both ?

This behavior is same for deleteMessage and deleteMessageBatch (error code is different if receipt handle is expired).

I also want to check the error code for changeMessageVisibility and changeMessageVisibilityBatch when receipt handle is expired (message exist with new receipt handle) ?

Note: I am using same receipt handle (valid but expired) for above SQS APIs.

1 Answer
1

When working with expired receipt handles in Amazon SQS, you're observing different error codes between the single-operation and batch-operation APIs. This difference is expected behavior in the SQS service.

For single operations like changeMessageVisibility and deleteMessage, when a receipt handle has expired, the service returns an HTTP 400 error with the error code "InvalidParameterValue" and a message indicating the receipt handle has expired.

For batch operations like changeMessageVisibilityBatch and deleteMessageBatch, the service handles errors differently. Instead of failing the entire batch request, it returns a per-message failure with the error code "ReceiptHandleIsInvalid" and sets the "SenderFault" flag to true.

This difference in error codes is by design. The batch operations are meant to process multiple messages in a single API call, and the service provides more specific error information for each message in the batch rather than failing the entire request.

Regarding your question about the error code when a receipt handle is expired but the message still exists with a new receipt handle: The behavior would be the same as what you're already seeing. When a visibility timeout expires, the message becomes visible again in the queue with a new receipt handle. Any attempts to use the old receipt handle (whether for changing visibility or deleting) would result in the same error patterns described above - "InvalidParameterValue" for single operations and "ReceiptHandleIsInvalid" for batch operations.

This is because once a receipt handle expires, it's no longer valid for any operations, regardless of whether the message still exists in the queue or has been deleted.
Sources
ChangeMessageVisibility - Amazon Simple Queue Service
AmazonSQSBufferedAsyncClient (AWS SDK for Java - 1.12.788)

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.