Skip to content

Instantly share code, notes, and snippets.

@fatihdumanli
Created November 3, 2020 11:30
Show Gist options
  • Save fatihdumanli/db33f0c79dceb7c2b33fa76fe74d328b to your computer and use it in GitHub Desktop.
Save fatihdumanli/db33f0c79dceb7c2b33fa76fe74d328b to your computer and use it in GitHub Desktop.
Using retries
public void TryConnect()
{
var policy = RetryPolicy.Handle<SocketException>().Or<BrokerUnreachableException>()
.WaitAndRetry(retryCount, op => TimeSpan.FromSeconds(Math.Pow(2, op)), (ex, time) =>
{
Console.WriteLine("Couldn't connect to RabbitMQ server...");
});
policy.Execute(() =>
{
_connection = factory.CreateConnection();
_isConnected = true;
Console.WriteLine("connected!");
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment