ChangeMessageVisibilityAsync() public method

Initiates the asynchronous execution of the ChangeMessageVisibility operation.
public ChangeMessageVisibilityAsync ( ChangeMessageVisibilityRequest request, System cancellationToken = default(CancellationToken) ) : Task
request Amazon.SQS.Model.ChangeMessageVisibilityRequest Container for the necessary parameters to execute the ChangeMessageVisibility operation.
cancellationToken System /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. ///
return Task
Beispiel #1
0
        private AsyncTask CreateRenewalTaskForMessage(Message message, AmazonSQSClient client)
        {
            var renewalTask = new AsyncTask(string.Format("RenewPeekLock-{0}", message.MessageId),
                async () =>
                {
                    _log.Info("Renewing peek lock for message with ID {0}", message.MessageId);

                    await client.ChangeMessageVisibilityAsync(new ChangeMessageVisibilityRequest(_queueUrl, message.ReceiptHandle, (int)_peekLockDuration.TotalSeconds));
                },
                prettyInsignificant: true)
                              {
                                  Interval = _peekLockRenewalInterval
                              };
            return renewalTask;
        }
        /// <summary>
        /// Rejects the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="requeue">if set to <c>true</c> [requeue].</param>
        public void Reject(Message message, bool requeue)
        {
            if (!message.Header.Bag.ContainsKey("ReceiptHandle"))
                return;

            var receiptHandle = message.Header.Bag["ReceiptHandle"].ToString();

            try
            {
                _logger.Value.InfoFormat("SqsMessageConsumer: Rejecting the message {0} with receipt handle {1} on the queue {2} with requeue paramter {3}", message.Id, receiptHandle, _queueUrl, requeue);
                
                using (var client = new AmazonSQSClient(_credentials))
                {
                    if (requeue)
                    {
                        client.ChangeMessageVisibilityAsync(new ChangeMessageVisibilityRequest(_queueUrl, receiptHandle, 0)).Wait();
                    }
                    else
                    {
                        client.DeleteMessageAsync(_queueUrl, receiptHandle).Wait();
                    }
                }

                _logger.Value.InfoFormat("SqsMessageConsumer: Message {0} with receipt handle {1} on the queue {2} with requeue paramter {3} has been rejected", message.Id, receiptHandle, _queueUrl, requeue);
            }
            catch (Exception exception)
            {
                _logger.Value.ErrorException("SqsMessageConsumer: Error during rejecting the message {0} with receipt handle {1} on the queue {2}", exception, message.Id, receiptHandle, _queueUrl);
                throw;
            }
        }
Beispiel #3
0
        IAsyncTask CreateRenewalTaskForMessage(Message message, AmazonSQSClient client)
        {
            return _asyncTaskFactory.Create($"RenewPeekLock-{message.MessageId}",
                async () =>
                {
                    _log.Info("Renewing peek lock for message with ID {0}", message.MessageId);

                    await
                        client.ChangeMessageVisibilityAsync(new ChangeMessageVisibilityRequest(_queueUrl,
                            message.ReceiptHandle, (int)_peekLockDuration.TotalSeconds));
                },
                intervalSeconds: (int)_peekLockRenewalInterval.TotalSeconds,
                prettyInsignificant: true);
        }