0

Edit: I will accept Azure configuration related changes as an answer to this question.


I am attempting to setup a retry policy to prevent instantly retrying a message when a 3rd party service is temporarily unavailable.

Currently the job is retried immediately multiple times and fails each time due to the temporary outage of the 3rd party service.

How do I set a retry delay for these messages?

I have the following code for Main:

class Program
{
    static void Main()
    {
        var config = new JobHostConfiguration();

        if (config.IsDevelopment)
            config.UseDevelopmentSettings();

        config.UseCore();
        config.UseServiceBus(new ServiceBusConfiguration()
        {
            ConnectionString = Configuration.GetAppSetting("Microsoft.ServiceBus.ConnectionString"),
            MessageOptions = new OnMessageOptions()
            {

            }
        });

        var host = new JobHost(config);

        LogManager.GetCurrentClassLogger().Information("F1.Birst.Automation web job starting.");
        // The following code ensures that the WebJob will be running continuously
        host.RunAndBlock();
    }
}

I have an ErrorMonitor setup which properly logs errors:

public class ExceptionHandler
{
    private static readonly ILogger Log = LogManager.GetCurrentClassLogger();

    public void Handle([ErrorTrigger] TraceFilter message, TextWriter log)
    {
        foreach (var exception in message.GetEvents())
            Log.Error(exception.Exception.InnerException, exception.Message);
    }
}

And my message handler looks like this:

public class ChurchCodeChangedEventHandler : ChurchSpaceHandler
{
    private static readonly ILogger Log = LogManager.GetCurrentClassLogger();

    public void Handle([ServiceBusTrigger(nameof(ChurchCodeChangedEvent), "F1.Birst.Automation.ChurchCodeChangedEvent")] ChurchCodeChangedEvent message, TextWriter log)
    {
        Log.Information(LogTemplates.ChurchCodeChanged, message.ChurchId);

        // snip
    }
}
Brett Allen
  • 5,297
  • 5
  • 32
  • 62

1 Answers1

1

How do I set a retry delay for these messages?

Webjobs do not support the concept of delayed retries. You can only control a few things using ServiceBusConfiguration, but those are not retries looking at the source code.

You could use frameworks like NServiceBus or MassTransit to get delayed retries. There's an example of how to use NServiceBus with WebJobs and you can run it locally to see how delayed retries would work.

Sean Feldman
  • 23,443
  • 7
  • 55
  • 80
  • I've used NServiceBus before and love it. Unfortunately it's not an option currently. Talking to our contact at Microsoft, and hoping they have some undocumented solution -_-;. – Brett Allen Nov 30 '17 at 14:43
  • 1
    You do not want to rely on undocumented solutions. Product Group will never give you such a thing. And if you get it from a Solutions Architect, question it. W/o native support for exact feature you will need to implement it yourself or use something else that does it for you. No magic – Sean Feldman Nov 30 '17 at 15:14