sendMessage method
Delivers a message to the specified queue.
#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.
May throw InvalidAddress.
May throw InvalidMessageContents.
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 UnsupportedOperation.
Parameter messageBody :
The message to send. The minimum size is one character. The maximum size
is 1 MiB or 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.
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 SQS 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 SQS 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 {
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.0',
'X-Amz-Target': 'AmazonSQS.SendMessage'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'MessageBody': messageBody,
'QueueUrl': queueUrl,
if (delaySeconds != null) 'DelaySeconds': delaySeconds,
if (messageAttributes != null) 'MessageAttributes': messageAttributes,
if (messageDeduplicationId != null)
'MessageDeduplicationId': messageDeduplicationId,
if (messageGroupId != null) 'MessageGroupId': messageGroupId,
if (messageSystemAttributes != null)
'MessageSystemAttributes':
messageSystemAttributes.map((k, e) => MapEntry(k.value, e)),
},
);
return SendMessageResult.fromJson(jsonResponse.body);
}