publishBatch method
Publishes up to 10 messages to the specified topic in a single batch. This
is a batch version of the Publish API. If you try to send
more than 10 messages in a single batch request, you will receive a
TooManyEntriesInBatchRequest exception.
For FIFO topics, multiple messages within a single batch are published in the order they are sent, and messages are deduplicated within the batch and across batches for five minutes.
The result of publishing 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 KB (262,144 bytes).
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
If you send a batch message to a topic, Amazon SNS publishes the batch message to each endpoint that is subscribed to the topic. The format of the batch message depends on the notification protocol for each subscribed endpoint.
When a messageId is returned, the batch message is saved, and
Amazon SNS immediately delivers the message to subscribers.
May throw AuthorizationErrorException.
May throw BatchEntryIdsNotDistinctException.
May throw BatchRequestTooLongException.
May throw EmptyBatchRequestException.
May throw EndpointDisabledException.
May throw InternalErrorException.
May throw InvalidBatchEntryIdException.
May throw InvalidParameterException.
May throw InvalidParameterValueException.
May throw InvalidSecurityException.
May throw KMSAccessDeniedException.
May throw KMSDisabledException.
May throw KMSInvalidStateException.
May throw KMSNotFoundException.
May throw KMSOptInRequired.
May throw KMSThrottlingException.
May throw NotFoundException.
May throw PlatformApplicationDisabledException.
May throw TooManyEntriesInBatchRequestException.
May throw ValidationException.
Parameter publishBatchRequestEntries :
A list of PublishBatch request entries to be sent to the SNS
topic.
Parameter topicArn :
The Amazon resource name (ARN) of the topic you want to batch publish to.
Implementation
Future<PublishBatchResponse> publishBatch({
required List<PublishBatchRequestEntry> publishBatchRequestEntries,
required String topicArn,
}) async {
final $request = <String, String>{
if (publishBatchRequestEntries.isEmpty)
'PublishBatchRequestEntries': ''
else
for (var i1 = 0; i1 < publishBatchRequestEntries.length; i1++)
for (var e3 in publishBatchRequestEntries[i1].toQueryMap().entries)
'PublishBatchRequestEntries.member.${i1 + 1}.${e3.key}': e3.value,
'TopicArn': topicArn,
};
final $result = await _protocol.send(
$request,
action: 'PublishBatch',
version: '2010-03-31',
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
resultWrapper: 'PublishBatchResult',
);
return PublishBatchResponse.fromXml($result);
}