sendMessage method
- required String messageBody,
- required String queueUrl,
- int? delaySeconds,
- Map<
String, MessageAttributeValue> ? messageAttributes, - String? messageDeduplicationId,
- String? messageGroupId,
- Map<
MessageSystemAttributeNameForSends, MessageSystemAttributeValue> ? messageSystemAttributes,
Delivers a message to the specified queue.
#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.
May throw InvalidMessageContents. May throw UnsupportedOperation.
Parameter messageBody :
The message to send. The minimum size is one character. The maximum size
is 256 KB.
#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.
Parameter queueUrl :
The URL of the Amazon SQS queue to which a message is sent.
Queue URLs and names are case-sensitive.
Parameter delaySeconds :
The length of time, in seconds, for which to delay a specific message.
Valid values: 0 to 900. Maximum: 15 minutes. Messages with a positive
DelaySeconds value become available for processing after the
delay period is finished. If you don't specify a value, the default value
for the queue applies.
Parameter messageAttributes :
Each message attribute consists of a Name, Type,
and Value. For more information, see Amazon
SQS Message Attributes in the Amazon Simple Queue Service Developer
Guide.
Parameter messageDeduplicationId :
This parameter applies only to FIFO (first-in-first-out) queues.
The token used for deduplication of sent messages. If a message with a
particular MessageDeduplicationId is sent successfully, any
messages sent with the same MessageDeduplicationId are
accepted successfully but aren't delivered during the 5-minute
deduplication interval. For more information, see
Exactly-Once Processing in the Amazon Simple Queue Service
Developer Guide.
-
Every message must have a unique
MessageDeduplicationId,-
You may provide a
MessageDeduplicationIdexplicitly. -
If you aren't able to provide a
MessageDeduplicationIdand you enableContentBasedDeduplicationfor your queue, Amazon SQS uses a SHA-256 hash to generate theMessageDeduplicationIdusing the body of the message (but not the attributes of the message). -
If you don't provide a
MessageDeduplicationIdand the queue doesn't haveContentBasedDeduplicationset, the action fails with an error. -
If the queue has
ContentBasedDeduplicationset, yourMessageDeduplicationIdoverrides the generated one.
-
You may provide a
-
When
ContentBasedDeduplicationis in effect, messages with identical content sent within the deduplication interval are treated as duplicates and only one copy of the message is delivered. -
If you send one message with
ContentBasedDeduplicationenabled and then another message with aMessageDeduplicationIdthat is the same as the one generated for the firstMessageDeduplicationId, the two messages are treated as duplicates and only one copy of the message is delivered.
Implementation
Future<SendMessageResult> sendMessage({
required String messageBody,
required String queueUrl,
int? delaySeconds,
Map<String, MessageAttributeValue>? messageAttributes,
String? messageDeduplicationId,
String? messageGroupId,
Map<MessageSystemAttributeNameForSends, MessageSystemAttributeValue>?
messageSystemAttributes,
}) async {
ArgumentError.checkNotNull(messageBody, 'messageBody');
ArgumentError.checkNotNull(queueUrl, 'queueUrl');
final $request = <String, dynamic>{};
$request['MessageBody'] = messageBody;
$request['QueueUrl'] = queueUrl;
delaySeconds?.also((arg) => $request['DelaySeconds'] = arg);
messageAttributes?.also((arg) => $request['MessageAttributes'] = arg);
messageDeduplicationId
?.also((arg) => $request['MessageDeduplicationId'] = arg);
messageGroupId?.also((arg) => $request['MessageGroupId'] = arg);
messageSystemAttributes?.also((arg) => $request['MessageSystemAttributes'] =
arg.map((k, v) => MapEntry(k.toValue(), v)));
final $result = await _protocol.send(
$request,
action: 'SendMessage',
version: '2012-11-05',
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
shape: shapes['SendMessageRequest'],
shapes: shapes,
resultWrapper: 'SendMessageResult',
);
return SendMessageResult.fromXml($result);
}