sendMessageBatch method

Future<SendMessageBatchResult> sendMessageBatch({
  1. required List<SendMessageBatchRequestEntry> entries,
  2. required String queueUrl,
})

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 1 MiB 1,048,576 bytes.

#x9 | #xA | #xD | #x20 to #xD7FF | #xE000 to #xFFFD | #x10000 to #x10FFFF

If a message contains characters outside the allowed set, Amazon SQS rejects the message and returns an InvalidMessageContents error. Ensure that your message body includes only valid characters to avoid this exception. If you don't specify the DelaySeconds parameter for an entry, Amazon SQS uses the default value for the queue.

May throw BatchEntryIdsNotDistinct. May throw BatchRequestTooLong. May throw EmptyBatchRequest. May throw InvalidAddress. May throw InvalidBatchEntryId. May throw InvalidSecurity. May throw KmsAccessDenied. May throw KmsDisabled. May throw KmsInvalidKeyUsage. May throw KmsInvalidState. May throw KmsNotFound. May throw KmsOptInRequired. May throw KmsThrottled. May throw QueueDoesNotExist. May throw RequestThrottled. May throw TooManyEntriesInBatchRequest. May throw UnsupportedOperation.

Parameter entries : A list of SendMessageBatchRequestEntry items.

Parameter queueUrl : The URL of the Amazon SQS queue to which batched messages are sent.

Queue URLs and names are case-sensitive.

Implementation

Future<SendMessageBatchResult> sendMessageBatch({
  required List<SendMessageBatchRequestEntry> entries,
  required String queueUrl,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.0',
    'X-Amz-Target': 'AmazonSQS.SendMessageBatch'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'Entries': entries,
      'QueueUrl': queueUrl,
    },
  );

  return SendMessageBatchResult.fromJson(jsonResponse.body);
}