title: Azure Service Bus Retry Options Not Working
body: <p>With no luck, I tried configuring my ServiceBusClient to retry a message with a Fixed Delay of 10 seconds.  I also tried Exponential retries configuration.  However, the code is always retrying the message within a second or 2 and completely ignoring the configuration.  It even ignores the MaxRetries and only retries 10 times, the value configured in Azure Portal for the queue.  What am I doing wrong?</p>
  <p>I am using The <a href="https://github.com/Azure/azure-sdk-for-net/blob/Azure.Messaging.ServiceBus_7.0.1/sdk/servicebus/Azure.Messaging.ServiceBus/README.md" rel="nofollow noreferrer">Azure.Messaging.ServiceBus</a> library, NuGet package 7.0.0.</p>
  <p>The code:</p>
  <pre><code>ServiceBusClient client = new ServiceBusClient(serviceBusConnectionString, new ServiceBusClientOptions()
              {
                  RetryOptions = new ServiceBusRetryOptions()
                  {
                      Mode = ServiceBusRetryMode.Fixed,
                      Delay = TimeSpan.FromSeconds(10),
                      MaxDelay = TimeSpan.FromMinutes(3),
                      MaxRetries = 30
                  }
              });
  
  ServiceBusProcessor processor = client.CreateProcessor(queueName, new ServiceBusProcessorOptions());
  
  // throwing an exception in MyMessageHandlerAsync on purpose
  // to test out the retries configuration
  processor.ProcessMessageAsync += MyMessageHandlerAsync;
  
  // The uncaught exception causes this method to execute. 
  // Processing is attempted 10 times with
  // virtually no delay between each attempt.
  // After the 10th attempt, the message goes to deadletter,
  // which is expected.
  processor.ProcessErrorAsync += MyErrorHandler;
  </code></pre>
  <hr />
  <p>I'm adding more to this question after receiving the 1st response:</p>
  <p>Currently, MyMessageHandlerAsync is:</p>
  <pre><code>    private async Task MyMessageHandlerAsync(EventArgs eventArgs)
      {
          var args = (ProcessMessageEventArgs)eventArgs;
  
          var body = args.Message.Body.ToString();
          
          // ...
          // process body
          // ...
  
          await args.CompleteMessageAsync(args.Message);
      }
  </code></pre>
  <p>How should I change the method's contents to retry a non-transient ServiceBusException?  Please help provide the code where the TODOs are below:</p>
  <pre><code>    private async Task MyMessageHandlerAsync(EventArgs eventArgs)
      {
          var args = (ProcessMessageEventArgs)eventArgs;
  
          try
          {
  
              var body = args.Message.Body.ToString();
          
              // ...
              // process body
              // ...
  
              await args.CompleteMessageAsync(args.Message);
          }
          catch (ServiceBusException sbe)
          {
              if (sbe.IsTransiet)
              {
                  // TODO: Is it correct that the exponential retry will work
                  // here?  The one defined in the ServiceBusClient.
                  // So, no code is needed here, just throw.
                  throw;
              }
              else
              {
                  // TODO: for non-transient, this is where the
                  //       options in the ServiceBusClient don't apply.
                  //       Is that correct?  How do I do an
                  //       exponential retry here?
              }
          }
          catch (Exception e)
          {
              // TODO: same problem as else in first catch.
          }
      }
  </code></pre>