SendMessageBatch
You can use SendMessageBatch
to send up to 10 messages to the specified
queue by assigning either identical or different values to each message (or by not
assigning values at all). This is a batch version of
SendMessage.
For a FIFO queue, multiple messages within a single batch are enqueued
in the order they are sent.
The result of sending each message is reported individually in the response.
Because the batch request can result in a combination of successful and unsuccessful actions, you should check for batch errors even when the call returns an HTTP status code of 200
.
The maximum allowed individual message size and the maximum total payload size (the sum of the individual lengths of all of the batched messages) are both 256 KiB (262,144 bytes).
A message can include only XML, JSON, and unformatted text. The following Unicode characters are allowed:
#x9
| #xA
| #xD
| #x20
to #xD7FF
| #xE000
to #xFFFD
| #x10000
to #x10FFFF
Any characters not included in this list will be rejected. For more information, see the W3C specification for characters
If you don't specify the DelaySeconds
parameter for an entry, Amazon SQS uses
the default value for the queue.
Some actions take lists of parameters. These lists are specified using the param.n
notation. Values of n
are integers starting from 1. For example, a parameter list with two elements looks like this:
&AttributeName.1=first
&AttributeName.2=second
Request Parameters
For information about the parameters that are common to all actions, see Common Parameters.
- QueueUrl
-
The URL of the Amazon SQS queue to which batched messages are sent.
Queue URLs and names are case-sensitive.
Type: String
Required: Yes
- SendMessageBatchRequestEntry.N
-
A list of
SendMessageBatchRequestEntry
items.Type: Array of SendMessageBatchRequestEntry objects
Required: Yes
Response Elements
The following elements are returned by the service.
- BatchResultErrorEntry.N
-
A list of
BatchResultErrorEntry
items with error details about each message that can't be enqueued.Type: Array of BatchResultErrorEntry objects
- SendMessageBatchResultEntry.N
-
A list of
SendMessageBatchResultEntry
items.Type: Array of SendMessageBatchResultEntry objects
Errors
For information about the errors that are common to all actions, see Common Errors.
- AWS.SimpleQueueService.BatchEntryIdsNotDistinct
-
Two or more batch entries in the request have the same
Id
.HTTP Status Code: 400
- AWS.SimpleQueueService.BatchRequestTooLong
-
The length of all the messages put together is more than the limit.
HTTP Status Code: 400
- AWS.SimpleQueueService.EmptyBatchRequest
-
The batch request doesn't contain any entries.
HTTP Status Code: 400
- AWS.SimpleQueueService.InvalidBatchEntryId
-
The
Id
of a batch entry in a batch request doesn't abide by the specification.HTTP Status Code: 400
- AWS.SimpleQueueService.TooManyEntriesInBatchRequest
-
The batch request contains more entries than permissible.
HTTP Status Code: 400
- AWS.SimpleQueueService.UnsupportedOperation
-
Error code 400. Unsupported operation.
HTTP Status Code: 400
Examples
Example
The following example SendMessageBatch
request sends two messages
to the queue. You must URL-encode the entire URL. However, in this example only the message body is URL-encoded to make the example easier to read. The structure of AUTHPARAMS
depends on the signature of the API request.
For more information, see
Examples of Signed Signature Version 4 Requests in the
AWS General Reference.
Sample Request
https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue/
?Action=SendMessageBatch
&SendMessageBatchRequestEntry.1.Id=test_msg_001
&SendMessageBatchRequestEntry.1.MessageBody=test%20message%20body%201
&SendMessageBatchRequestEntry.2.Id=test_msg_002
&SendMessageBatchRequestEntry.2.MessageBody=test%20message%20body%202
&SendMessageBatchRequestEntry.2.DelaySeconds=60
&SendMessageBatchRequestEntry.2.MessageAttribute.1.Name=test_attribute_name_1
&SendMessageBatchRequestEntry.2.MessageAttribute.1.Value.StringValue=test_attribute_value_1
&SendMessageBatchRequestEntry.2.MessageAttribute.1.Value.DataType=String
&Expires=2020-05-05T22%3A52%3A43PST
&Version=2012-11-05
&AUTHPARAMS
Sample Response
<SendMessageBatchResponse>
<SendMessageBatchResult>
<SendMessageBatchResultEntry>
<Id>test_msg_001</Id>
<MessageId>0a5231c7-8bff-4955-be2e-8dc7c50a25fa</MessageId>
<MD5OfMessageBody>0e024d309850c78cba5eabbeff7cae71</MD5OfMessageBody>
</SendMessageBatchResultEntry>
<SendMessageBatchResultEntry>
<Id>test_msg_002</Id>
<MessageId>15ee1ed3-87e7-40c1-bdaa-2e49968ea7e9</MessageId>
<MD5OfMessageBody>7fb8146a82f95e0af155278f406862c2</MD5OfMessageBody>
<MD5OfMessageAttributes>295c5fa15a51aae6884d1d7c1d99ca50</MD5OfMessageAttributes>
</SendMessageBatchResultEntry>
</SendMessageBatchResult>
<ResponseMetadata>
<RequestId>ca1ad5d0-8271-408b-8d0f-1351bf547e74</RequestId>
</ResponseMetadata>
</SendMessageBatchResponse>
Example
The following example sends multiple messages with message
timers—applying a visibility delay of variable length to
the messages in the batch—by calling the SendMessageBatch
action without a value for DelaySeconds
for
the first message and with the values of 45 seconds and 2 minutes for the second
and third messages.
If you don't set a value for the DelaySeconds
parameter, the
message might still be subject to a delay if you add the message to a
delay queue. For more information about using delay
queues, see Amazon SQS Delay Queues in the Amazon SQS Developer
Guide.
Sample Request
https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue/
?Action=SendMessageBatch
&SendMessageBatchRequestEntry.1.Id=test_msg_no_message_timer
&SendMessageBatchRequestEntry.1.MessageBody=test%20message%20body%201
&SendMessageBatchRequestEntry.2.Id=test_msg_delay_45_seconds
&SendMessageBatchRequestEntry.2.MessageBody=test%20message%20body%202
&SendMessageBatchRequestEntry.2.DelaySeconds=45
&SendMessageBatchRequestEntry.3.Id=test_msg_delay_2_minutes
&SendMessageBatchRequestEntry.3.MessageBody=test%20message%20body%203
&SendMessageBatchRequestEntry.3.DelaySeconds=120
&Expires=2020-12-18T22%3A52%3A43PST
&Version=2012-11-05
&AUTHPARAMS
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: