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

CreateQueueAsync() public method

Initiates the asynchronous execution of the CreateQueue operation.
public CreateQueueAsync ( CreateQueueRequest request, CreateQueueResponse>.AmazonServiceCallback callback, AsyncOptions options = null ) : void
request Amazon.SQS.Model.CreateQueueRequest Container for the necessary parameters to execute the CreateQueue operation on AmazonSQSClient.
callback CreateQueueResponse>.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 CreateQueueAsync(CreateQueueRequest request, AmazonServiceCallback<CreateQueueRequest, CreateQueueResponse> callback, AsyncOptions options = null)
        {
            options = options == null?new AsyncOptions():options;
            var marshaller = new CreateQueueRequestMarshaller();
            var unmarshaller = CreateQueueResponseUnmarshaller.Instance;
            Action<AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null;
            if(callback !=null )
                callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => { 
                    AmazonServiceResult<CreateQueueRequest,CreateQueueResponse> responseObject 
                            = new AmazonServiceResult<CreateQueueRequest,CreateQueueResponse>((CreateQueueRequest)req, (CreateQueueResponse)res, ex , ao.State);    
                        callback(responseObject); 
                };
            BeginInvoke<CreateQueueRequest>(request, marshaller, unmarshaller, options, callbackHelper);
        }

Same methods

AmazonSQSClient::CreateQueueAsync ( CreateQueueRequest request, System cancellationToken = default(CancellationToken) ) : Task
AmazonSQSClient::CreateQueueAsync ( string queueName, System cancellationToken = default(CancellationToken) ) : Task
AmazonSQSClient::CreateQueueAsync ( string queueName, CreateQueueResponse>.AmazonServiceCallback callback, AsyncOptions options = null ) : void

Usage Example

Example #1
0
        /// <summary>
        /// Ensure sqs queue creation
        /// </summary>
        /// <param name="snsTopicArn">Subscribe to a sns topic</param>
        /// <returns></returns>
        public async Task EnsureQueueCreationAsync(string snsTopicArn = null)
        {
            // an integer representing seconds, from 60 (1 minute) to 1,209,600 (14 days). Default: 345,600 (4 days).
            var messageRetentionPeriod = "1209600";

            using (var client = new Amazon.SQS.AmazonSQSClient(accessKey, secretKey, region))
            {
                // dead letter queue
                var req = new CreateQueueRequest("dead-" + queueName);
                req.Attributes.Add(QueueAttributeName.MessageRetentionPeriod, messageRetentionPeriod);
                if (isFIFO)
                {
                    req.Attributes.Add(QueueAttributeName.FifoQueue, "true");
                }

                var r = await client.CreateQueueAsync(req);

                string deadQueueArn = r.QueueUrl
                                      .Replace("https://sqs.", "arn:aws:sqs:")
                                      .Replace(".amazonaws.com", "")
                                      .Replace("/", ":");

                // queue
                req = new CreateQueueRequest(queueName);
                req.Attributes.Add(QueueAttributeName.MessageRetentionPeriod, messageRetentionPeriod);
                req.Attributes.Add(QueueAttributeName.RedrivePolicy, "{\"maxReceiveCount\":3, \"deadLetterTargetArn\": \"" + deadQueueArn + "\"}");
                if (isFIFO)
                {
                    req.Attributes.Add(QueueAttributeName.FifoQueue, "true");
                }

                r = await client.CreateQueueAsync(req);

                // subscribe to sns topic
                if (!string.IsNullOrEmpty(snsTopicArn))
                {
                    await notificationService.SubscribeSQS(snsTopicArn, client, r.QueueUrl);
                }
            }
        }
AmazonSQSClient