Implementing retry logic for Azure Caching applications made easy!
Applications using Azure cache might commonly encounter exceptions similar to below while performing cache operations like get, put. We refer to these kind of errors as transient errors. Developer is required to implement retry logic in the application code to shield the application from transient errors.
ErrorCode<ERRCA0017>:SubStatus<ES0006>:There is a temporary failure. Please retry later. (One or more specified cache servers are unavailable, which could be caused by busy network or servers. For on-premises cache clusters, also verify the following conditions. Ensure that security permission has been granted for this client account, and check that the AppFabric Caching Service is allowed through the firewall on all cache hosts. Also the MaxBufferSize on the server must be greater than or equal to the serialized object size sent from the client.)
Thanks to "Transient fault handling application block" from patterns & practices team. It is now very easy to implement sophisticated retry logic in your application. I'm describing the instructions in 3 steps here.
Add the Transient Fault Handling Application Block to your application
- Install latest version of NuGet from here https://nuget.org/.
- Add a reference to the Transient Fault Handling Application Block assemblies. In Microsoft Visual Studio, right-click your project node in Solution Explorer, and then click Manage NuGet Packages.
- Click the Online button, and then in the Search Online box, type topaz.
- Click the Install button for the Enterprise Library 5.0 - Transient Fault Handling Application Block package.
- Read and accept the license terms for the packages listed.
- After NuGet has finished installing the packages, click Close.
- NuGet has now updated your project with all the necessary assemblies and references that you need to use the Transient Fault Handling Application Block. The project now also includes a readme file that contains important information about the Transient Fault Handling Application Block.
Configure retry policy for your application.
Make azure cache calls inside ExecuteAction delegate as shown below.
Download the sample source code here
References
Windows Server AppFabric Caching - Table of Error Code Strings
https://msdn.microsoft.com/en-us/library/ff921008.aspx
Exception Handling Overview (Windows Server AppFabric Caching) – Also applicable to Azure AppFabric Caching
https://msdn.microsoft.com/en-us/library/ff637738.aspx
Handling Errors
https://msdn.microsoft.com/en-us/library/ff637704.aspx
Application Exceptions (Windows Server AppFabric Caching)
https://msdn.microsoft.com/en-us/library/ff921006.aspx
Transient Fault Handling
https://msdn.microsoft.com/en-us/library/hh680901(v=PandP.50).aspx
Post your comments, feedback using comments section below!
Comments
Anonymous
June 11, 2012
I have seen plenty of examples of what's described above. And it's awesome - thank you very much! However I do have a question: How do you implement retry mechanisms in situations where you want to return data from the call inside the "ExecuteAction" deleagte? Cheers, KyryllAnonymous
May 06, 2014
You will definitely need something like this because the cache is completely unreliable and unsuitable for production use.