SendMessageBatchAsync() 공개 메소드

Initiates the asynchronous execution of the SendMessageBatch operation.
public SendMessageBatchAsync ( SendMessageBatchRequest request, System cancellationToken = default(CancellationToken) ) : Task
request Amazon.SQS.Model.SendMessageBatchRequest Container for the necessary parameters to execute the SendMessageBatch operation.
cancellationToken System /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. ///
리턴 Task
        private static async Task MainAsync(string[] args)
        {
            var sqsClient = new Amazon.SQS.AmazonSQSClient();

            for (var idx = 0; idx <= 50000; idx++)
            {
                Console.WriteLine(String.Format("BATCH No.: {0}", idx));
                var sendMessageBatchRequest = new SendMessageBatchRequest
                {
                    Entries  = generateMessages(),
                    QueueUrl = "https://sqs.eu-west-1.amazonaws.com/655379451354/4developers_queue"
                };
                var resonse = await sqsClient.SendMessageBatchAsync(sendMessageBatchRequest);
            }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="messages"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task SendBatchAsync(string[] messages, CancellationToken token)
        {
            Console.WriteLine(string.Format("Sending {0} messages: ", messages.Length));

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

                var queueUrl = queueUrlResult.QueueUrl;

                var entries = new List <SendMessageBatchRequestEntry>();
                foreach (var message in messages)
                {
                    var req = new SendMessageBatchRequestEntry(Guid.NewGuid().ToString(), message);
                    if (isFIFO)
                    {
                        // required
                        req.MessageGroupId         = "group"; // fifo atua sobre o grupo
                        req.MessageDeduplicationId = Guid.NewGuid().ToString();
                    }

                    entries.Add(req);
                }

                var batch = new SendMessageBatchRequest(queueUrl, entries);
                var r     = await client.SendMessageBatchAsync(batch);

                if (r.Failed != null && r.Failed.Count > 0)
                {
                    foreach (var f in r.Failed)
                    {
                        Console.WriteLine("Failed : ", f.Message);
                    }
                }
            }
        }