Exemplo n.º 1
0
 /// <inheritdoc/>
 public async Task KeepAliveAsync(IEnumerable <Message> messages, TimeSpan?timeToLive = null, CancellationToken cancellationToken = default)
 {
     var response = await _client.ChangeMessageVisibilityBatchAsync(new ChangeMessageVisibilityBatchRequest
     {
         QueueUrl = await GetQueueUrl().ConfigureAwait(false),
         Entries  = messages.Select(m => new ChangeMessageVisibilityBatchRequestEntry
         {
             Id                = m.Id,
             ReceiptHandle     = (string)m.SystemProperties[ReceiptHandleProperty],
             VisibilityTimeout = timeToLive.HasValue ? (int)timeToLive.Value.TotalSeconds : 60 * 3
         }).ToList()
     }, cancellationToken).ConfigureAwait(false);
 }
Exemplo n.º 2
0
        public async Task ChangeMessageVisibilityBatch()
        {
            // Create service client using the SDK's default logic for determining AWS credentials and region to use.
            // For information configuring service clients checkout the .NET developer guide: https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/net-dg-config.html
            AmazonSQSClient client   = new AmazonSQSClient();
            string          queueUrl = "SQS_QUEUE_URL";

            var receiveMessageRequest = new ReceiveMessageRequest
            {
                AttributeNames        = { "SentTimestamp" },
                MaxNumberOfMessages   = 5,
                MessageAttributeNames = { "All" },
                QueueUrl = queueUrl
            };

            var receiveMessageResponse = await client.ReceiveMessageAsync(receiveMessageRequest);

            List <ChangeMessageVisibilityBatchRequestEntry> entries = new List <ChangeMessageVisibilityBatchRequestEntry>();

            foreach (var message in receiveMessageResponse.Messages)
            {
                entries.Add(new ChangeMessageVisibilityBatchRequestEntry
                {
                    Id                = message.MessageId,
                    ReceiptHandle     = message.ReceiptHandle,
                    VisibilityTimeout = 36000, // 10 hour timeout
                });
            }

            var changeMessageVisibilityBatchResponse = await client.ChangeMessageVisibilityBatchAsync(new ChangeMessageVisibilityBatchRequest
            {
                QueueUrl = queueUrl,
                Entries  = entries
            });

            Console.WriteLine("Messages successfully changed:");
            foreach (var success in changeMessageVisibilityBatchResponse.Successful)
            {
                Console.WriteLine("    Message id : {0}", success.Id);
            }

            Console.WriteLine("Messages failed to change:");
            foreach (var failed in changeMessageVisibilityBatchResponse.Failed)
            {
                Console.WriteLine("    Message id : {0}", failed.Id);
                Console.WriteLine("    Sender's fault? : {0}", failed.SenderFault);
            }
        }