locked
QueueRequestOptions are not applied to a Queue RRS feed

  • Question

  • I need to add queue message with specific retry logic: time between retries 30mins and maximum 10 retries. I tried to use QueueRequestOptions in all found places but inteval between retries was not changed as I wanted. My test class which creates queue and adds messages:

    using Microsoft.WindowsAzure.Storage;
    using Microsoft.WindowsAzure.Storage.Queue;
    using Microsoft.WindowsAzure.Storage.RetryPolicies;

        public class QueueHelper
        {

            public const string TEST_QUEUE = "test-queue";

            private CloudStorageAccount _GeneralStorageAccount;
            private CloudStorageAccount GeneralStorageAccount
            {
                get
                {
                    if (_GeneralStorageAccount == null)
                    { _GeneralStorageAccount = CloudStorageAccount.Parse("ConnectionString"); }
                    return _GeneralStorageAccount;
                }
            }

            private CloudQueueClient _QueueClient;
            private CloudQueueClient QueueClient
            {
                get
                {
                    if (_QueueClient == null)
                    {
                        _QueueClient = GeneralStorageAccount.CreateCloudQueueClient();
                        _QueueClient.DefaultRequestOptions = GetQueueRequestOptions();
                    }
                    return _QueueClient;
                }
            }


            private CloudQueue _TestQueue;
            private CloudQueue TestQueue
            {
                get
                {
                    if (_TestQueue == null)
                    {
                        // Create queue 
                        _TestQueue = QueueClient.GetQueueReference(TEST_QUEUE);
                        _TestQueue.CreateIfNotExists(GetQueueRequestOptions());
                    }
                    return _TestQueue;
                }
            }

            public void AddErrorsQueueMessage(string message)
            {
                CloudQueueMessage Message = new CloudQueueMessage(message);
                TestQueue.AddMessage(Message);
            }
      
            private QueueRequestOptions GetQueueRequestOptions()
            {
                System.TimeSpan DeltaBackoff = new System.TimeSpan(hours: 0,minutes: 30,seconds: 0);
                int MaxAttempts = 10;
                ExponentialRetry ExponentialRetryPolicy = new ExponentialRetry(deltaBackoff: DeltaBackoff,maxAttempts: MaxAttempts);

                System.TimeSpan MaximumExecutionTime = new System.TimeSpan(days: 5, hours: 0,minutes: 0,seconds: 0);

                //LinearRetry LinearRetryPolicy = new LinearRetry(deltaBackoff: DeltaBackoff, maxAttempts: MaxAttempts);

                QueueRequestOptions Options = new QueueRequestOptions { RetryPolicy = ExponentialRetryPolicy,
                                                                        MaximumExecutionTime = MaximumExecutionTime };

                return Options;
            }

        }

    Tuesday, August 8, 2017 3:30 PM

All replies

  • Have you checked the suggestions given for a similar storage queue retry logic in this thread? If not, you might want to refer those and see if it helps. Also, what service are you trying to integrate with Azure queues?

    -----------------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.

    Wednesday, August 9, 2017 4:20 AM
  • I have a web job which process messages from this queue. My test web job which imitates that message can not be processed:

     ' This function will get triggered/executed when a new message is written 
        ' on an Azure Queue called queue.
        Public Sub ProcessQueueMessage(<QueueTrigger("test-queue")> message As String, log As TextWriter)
            AddLog(message)
            Throw New Exception("Something went wrong")
        End Sub

    The thread you mentioned is really very similar to my problem by unfortunately no working answers are provided there. The idea to add and delete messages manually and also count somewhere the amount of attempts means that all Retry classes are useless which I hope is not true. The idea to use RetryPolicy while adding queue message does not work.

    Wednesday, August 9, 2017 5:59 AM