antonyvorontsov / RabbitMQ.Client.Core.DependencyInjection

.Net Core library-wrapper of RabbitMQ.Client for Dependency Injection.
MIT License
111 stars 36 forks source link

Retry mechanism for when the rabbit mq server instance is down? #41

Closed adzhazhev closed 4 years ago

adzhazhev commented 4 years ago

Hi,

A lot of thanks for the library. It's really easy to use. I went through the documentation but I didn't see a way of retrying to reconnect if the first try to connect fails? Any suggestions?

Regards Alex

antonyvorontsov commented 4 years ago

Hi, Alexander!

Yup. you are right, there is no such functionality yet. Thank you for the suggestion, I will try to implement initial retries in the upcoming releases.

Best regards, Antony

antonyvorontsov commented 4 years ago

Alexandr, hi again!

I have implemented a retry mechanism and now you can configure that behaviour. I covered this feature in this documentation file, but I will duplicate instructions here.

For now you can set new properties InitialConnectionRetries and InitialConnectionRetryTimeoutMilliseconds in a configuration section

{
 "RabbitMq": {
    "HostName": "127.0.0.1",
    "Port": "5672",
    "UserName": "guest",
    "Password": "guest",
    "VirtualHost": "/",
    "InitialConnectionRetries": 5,
    "InitialConnectionRetryTimeoutMilliseconds": 200
  }
}

Values of those properties will be used when RabbitMqConnectionFactory try to create an initial connection. "InitialConnectionRetries": 5 and "InitialConnectionRetryTimeoutMilliseconds": 200 accordingly are default values, but if you think that you need more retries or another timeout you can change it.

PR is right here https://github.com/AntonyVorontsov/RabbitMQ.Client.Core.DependencyInjection/pull/43

I will try to release a new version of the library in a couple of days. Best regards, Antony

antonyvorontsov commented 4 years ago

This feature is now released with version 4.1.0. Try it out!

Closing the issue. If there is any other questions, feel free to re-open it.

Best regards, Antony