Created
November 3, 2020 11:30
-
-
Save fatihdumanli/db33f0c79dceb7c2b33fa76fe74d328b to your computer and use it in GitHub Desktop.
Using retries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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