Amazon.SQS.AmazonSQSClient.CreateQueueAsync C# (CSharp) 메소드

CreateQueueAsync() 공개 메소드

Initiates the asynchronous execution of the CreateQueue operation.
public CreateQueueAsync ( CreateQueueRequest request, System cancellationToken = default(CancellationToken) ) : Task
request Amazon.SQS.Model.CreateQueueRequest Container for the necessary parameters to execute the CreateQueue operation.
cancellationToken System /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. ///
리턴 Task
        public Task<CreateQueueResponse> CreateQueueAsync(CreateQueueRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new CreateQueueRequestMarshaller();
            var unmarshaller = CreateQueueResponseUnmarshaller.Instance;

            return InvokeAsync<CreateQueueRequest,CreateQueueResponse>(request, marshaller, 
                unmarshaller, cancellationToken);
        }

Same methods

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

Usage 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