0

Not sure what is wrong with my retry policy logic with Service Bus 1.1. We are not able to use Azure service bus. I have tried several different configurations but still no luck getting it to fire. It will just move right to the exception.

TokenProvider provider = TokenProvider.CreateSharedAccessSignatureTokenProvider("RootManageSharedAccessKey", "<key goes here>");
var retryPolicy = new RetryExponential(TimeSpan.FromSeconds(10), TimeSpan.FromMinutes(3),
                TimeSpan.FromSeconds(10), TimeSpan.FromMinutes(5), 1000);
var _factory = MessagingFactory.Create("<Namespace Address>", provider);
var _sender = _factory.CreateMessageSender("Analytics");
_sender.RetryPolicy = retryPolicy;
var message = new BrokeredMessage("message");
try
{
   _sender.Send(message);
}
catch(Exception e) 
{
    Console.WriteLine(e);
}

I've made the retry policy abnormally large for testing purposes. As far as I can tell it never retries the message. I've tested the various exceptions including those where istransient is true.

I have read through these posts and articles already:

Has anyone ever ran into this before? I hope i'm just missing something simple.

Community
  • 1
  • 1
J - Mac
  • 21
  • 1
  • 3
  • what is the error message reported? – Raj Feb 16 '17 at 17:36
  • The retry policy is supposed to try and re-send the message before the exception is thrown. That's what i'm asking, why is not doing that? There is no error message, it simply doesn't retry. We are simulating service bus failures. The exceptions are working as desired, the retry never happens. It immediately throws the exception . – J - Mac Feb 16 '17 at 17:52
  • @J-Mac - could you please elaborate more on how did you simulate service bus failures. I am currently facing the same issue that you have mentioned in your question and I want to see if my retry logic is working or not... – gkb Jun 09 '17 at 14:17

2 Answers2

0

Retry mechanism works like this

The exceptions returned from Service Bus expose the IsTransient property that indicates if the client should retry the operation. The built-in RetryExponential policy relies on the IsTransient property in the MessagingException class, which is the base class for all Service Bus exceptions.

check the OperationTimeout

console.WriteLine(_factory.GetSettings().OperationTimeout);

If the value is less than maxBackoff then set the OperationTimeout higher than maxBackoff

_factory.GetSettings().OperationTimeout = TimeSpan.FromMinutes(6);

after creating MessageFactory

Raj
  • 1,156
  • 11
  • 15
  • Yes, I have read that and as stated in the question I have verified that IsTransient is true. Exceptions we are testing are MessagingExceptions (although in the code sample provided I used a generic one). – J - Mac Feb 16 '17 at 18:12
  • The maxBackoff is more than the OperationTimeout (default one minute), set OperationTimeout more than maxBackoff in MessagingFactorySettings – Raj Feb 16 '17 at 18:40
  • I made the update to OperationTimeout as suggested but the behavior is the same. The retry never happens. – J - Mac Feb 16 '17 at 20:12
  • sorry for dragging you, I think the terminationTimeBuffer is a buffer time after termination and before retry, try some thing to seconds TimeSpan.FromSeconds(5) insted of TimeSpan.FromMinutes(5) – Raj Feb 16 '17 at 20:26
  • No worries, appreciate the help. I made the change but have the same issue. Have you ever seen a working retry policy on a message sender? – J - Mac Feb 16 '17 at 21:33
0

I found this blog post:

Right-click your project in Solution Explorer and select Manage NuGet Packages. Type Transient Fault Handling in the Search box and click Search. Select Enterprise Library - Transient Fault Handling Application Block package. After you click Install, a set of necessary assemblies and references that support the Transient Fault Handling Application Block will be added to the project.

After implementing the interface I was able to successfully execute a retry policy.

I'm still not sure why the default one would not work though.

J - Mac
  • 21
  • 1
  • 3