sendMessage method

Future<SendMessageResult> sendMessage({
  1. required String messageBody,
  2. required String queueUrl,
  3. int? delaySeconds,
  4. Map<String, MessageAttributeValue>? messageAttributes,
  5. String? messageDeduplicationId,
  6. String? messageGroupId,
  7. 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 MessageDeduplicationId explicitly.
    • If you aren't able to provide a MessageDeduplicationId and you enable ContentBasedDeduplication for your queue, Amazon SQS uses a SHA-256 hash to generate the MessageDeduplicationId using the body of the message (but not the attributes of the message).
    • If you don't provide a MessageDeduplicationId and the queue doesn't have ContentBasedDeduplication set, the action fails with an error.
    • If the queue has ContentBasedDeduplication set, your MessageDeduplicationId overrides the generated one.
  • When ContentBasedDeduplication is 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 ContentBasedDeduplication enabled and then another message with a MessageDeduplicationId that is the same as the one generated for the first MessageDeduplicationId, 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);
}