Endjin - Home

Extending Endjin.Retry with custom Retry Policies

by Howard van Rooijen

Someone tweeted @endjin this week to ask if we were still supporting our Endjin.Retry framework; they asked because they were worried it had been abandoned because it had only had 6 minor commits in 2014. I replied to confirm that we have not abandoned this project in the slightest, in fact it’s one of our most used, core bits of IP (along with Endjin.Composition), that we use in practically every project we develop whether it’s related specifically to Azure or not. We have found that it is easier to extend Endjin.Retry, through its IRetryPolicy and IRetryStrategy inside the consuming project rather than pollute the core library – this means all of these customisations happen in our private project repos, not in the public Endjin.Retry repo.

Below are a series of examples of custom retry policies we’ve implemented in various projects:

HttpRequestExceptionRetryPolicy

This a very simple retry policy that will retry if a HttpRequestException is encountered. A good general purpose transient HTTP error retry strategy

DoNotRetryOnConflictPolicy

This retry policy was specifically designed to work with the Azure Storage SDK will retry on any exception except for a HTTP 409 Conflict status code – a scenario whereby the resource you’re trying to create already exists.

DoNotRetryOn304NotModified

Similar to the previous policy, this retry policy will retry except for a HTTP 304 Not Modified status code.

StorageWriteExceptionRetryPolicy

The following retry policy was created to retry except in the event of a HTTP Protocol error or a HTTP 409 Conflict status code

DoNotRetryOnLeaseAcquisitionUnsuccessfulPolicy

This retry policy is part of our Endjin.Leasing framework, which implements Mutex operations over Azure Blob Storage and will retry unless a LeaseAcquisitionUnsuccessfulException is detected, and would enable a scenario whereby you’d have a series of competing actors who want perform an action against a specific resource, the first to obtain the Mutex wins and the other actors fail fast.

RetryUntilLeaseAcquiredPolicy

This retry policy is also part of our Endjin.Leasing framework but enables the opposite scenario than the previous policy; if multiple actors want to perform an action on a particular resource, the should retry until the obtain their Mutex:

Hopefully these examples show how easy it is to implement your own retry policies, which nicely encapsulate your success and failure conditions.

@HowardvRooijen

Sign up to Azure Weekly to receive Azure related news and articles direct to your inbox every Sunday, or follow @azureweekly on Twitter.

About the author

Howard spent 10 years as a technology consultant helping some of the UK's best known organisations work smarter, before founding endjin in 2010. He's a Microsoft Accelerator Mentor, and a Microsoft Azure MVP. You can follow him on Twitter via @HowardvRooijen