Amit's Blog

Sharing Thoughts and Learning

  Home  |   Contact  |   Syndication    |   Login
  43 Posts | 1 Stories | 153 Comments | 14 Trackbacks

News

About Me?
Read it in
Blog Statistics
Proud Member of

Archives

Post Categories

Articles

Book Review

I Visit.

OpenSource Project(s)

 

When consuming any external service, don't expect the external service developer is as much smart as you are. Recently I have faced an issue when integrating with Amazon S3 that they failed to serve the data on first request, but on the consequent request they are able to return the data. So I did a little tweak in my code, instead of calling the service once, I am retrying up to 3 times. If the retry also fails the regular code block executes:
const int MAX_TRY = 3;
int tryCount = 1;
byte[] result = null;

using(AmazonS3 proxy = CreateServiceProxy())
{
while(((result == null) || (result.Length == 0)) && (tryCount < MAX_TRY))
{
try
{
result = proxy.GetObject(_bucketName, key, false, true, true, _accessKeyID, timestamp, true, signature, null).Data;
}
catch
{
tryCount += 1;

if (tryCount == MAX_TRY)
{
throw;
}
}
}
}

return result;
posted on Saturday, January 13, 2007 11:18 PM