Amazon.SQS.AmazonSQSClient.SendMessageAsync C# (CSharp) Method

SendMessageAsync() public method

Delivers a message to the specified queue.

The following list shows the characters (in Unicode) that are allowed in your message, according to the W3C XML specification:

  • #x9

  • #xA

  • #xD

  • #x20 to #xD7FF

  • #xE000 to #xFFFD

  • #x10000 to #x10FFFF

For more information, see RFC1321. If you send any characters that aren't included in this list, your request is rejected.

/// The message contains characters outside the allowed set. /// /// Error code 400. Unsupported operation. ///
public SendMessageAsync ( string queueUrl, string messageBody, System cancellationToken = default(CancellationToken) ) : Task
queueUrl string The URL of the Amazon SQS queue to which a message is sent. Queue URLs are case-sensitive.
messageBody string The message to send. The maximum string size is 256 KB. The following list shows the characters (in Unicode) that are allowed in your message, according to the W3C XML specification:
  • #x9
  • #xA
  • #xD
  • #x20 to #xD7FF
  • #xE000 to #xFFFD
  • #x10000 to #x10FFFF
For more information, see RFC1321. If you send any characters that aren't included in this list, your request is rejected.
cancellationToken System /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. ///
return Task
        public Task<SendMessageResponse> SendMessageAsync(string queueUrl, string messageBody, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var request = new SendMessageRequest();
            request.QueueUrl = queueUrl;
            request.MessageBody = messageBody;
            return SendMessageAsync(request, cancellationToken);
        }

Same methods

AmazonSQSClient::SendMessageAsync ( SendMessageRequest request, System cancellationToken = default(CancellationToken) ) : Task
AmazonSQSClient::SendMessageAsync ( SendMessageRequest request, SendMessageResponse>.AmazonServiceCallback callback, AsyncOptions options = null ) : void
AmazonSQSClient::SendMessageAsync ( string queueUrl, string messageBody, SendMessageResponse>.AmazonServiceCallback callback, AsyncOptions options = null ) : void

Usage Example

Example #1
0
        public async Task SendAsync(string message, CancellationToken token)
        {
            // Console.WriteLine("Sending messages:");

            using (var client = new Amazon.SQS.AmazonSQSClient(accessKey, secretKey, region))
            {
                var queueUrlResult = await client.GetQueueUrlAsync(queueName, token);

                var queueUrl = queueUrlResult.QueueUrl;

                var req = new SendMessageRequest(queueUrl, message);
                if (isFIFO)
                {
                    // required
                    req.MessageGroupId         = "group";
                    req.MessageDeduplicationId = message;
                }
                req.MessageAttributes.Add("CorrelationID", new MessageAttributeValue()
                {
                    DataType    = "string",
                    StringValue = Guid.NewGuid().ToString()
                });
                //req.DelaySeconds = 10;

                var r = await client.SendMessageAsync(req);

                Console.WriteLine("[" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff") + "] [P] " + message + " | " + r.MessageId);
            }
        }
All Usage Examples Of Amazon.SQS.AmazonSQSClient::SendMessageAsync
AmazonSQSClient