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, SendMessageResponse>.AmazonServiceCallback callback, AsyncOptions options = null ) : void
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.
callback SendMessageResponse>.AmazonServiceCallback An Action delegate that is invoked when the operation completes.
options Amazon.Runtime.AsyncOptions /// A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property. ///
return void
        public void SendMessageAsync(string queueUrl, string messageBody,  AmazonServiceCallback<SendMessageRequest, SendMessageResponse> callback, AsyncOptions options = null)
        {
            var request = new SendMessageRequest();
            request.QueueUrl = queueUrl;
            request.MessageBody = messageBody;
            SendMessageAsync(request, callback, options);
        }

Same methods

AmazonSQSClient::SendMessageAsync ( SendMessageRequest request, System cancellationToken = default(CancellationToken) ) : Task
AmazonSQSClient::SendMessageAsync ( string queueUrl, string messageBody, System cancellationToken = default(CancellationToken) ) : Task
AmazonSQSClient::SendMessageAsync ( SendMessageRequest request, 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