Closed MohammadAkbari closed 4 years ago
Hello Mohammad.
Unfortunately you can not do that using the latest version of the library. The only possible workaround is to deploy as much instances of your application as number of replicas in the RabbitMQ cluster. But this workaround is only acceptable for small applications (a.k.a. micro services) and I am not sure that this solution can fit your claims.
I will add a way to connect multiple hostnames as soon as possible in the future versions of the library. And I am gonna patch both version for .Net Core 2.2 and .Net Core 3.0.
I will keep you updated of my progress.
Regards, Antony
Thank you for your attention to this matter. Your library is very straightforward in usage. I hope that you add this feature. Thanks a lot
Mohammad, hi!
I added this feature. Now you can connect multiple hosts different ways.
So there are three properties in RabbitMqClientOptions
class now. You can either set one hostname (HostName
property), collection of hostnames (HostNames
property) or collection of endpoints where endpoint is a pair of hostname and port values (TcpEndpoints
property).
If you use appsettings.json and, I am completely sure that you do, you can change your configuration from this
{
"RabbitMq": {
"HostName": "127.0.0.1",
"Port": "5672",
"UserName": "guest",
"Password": "guest"
}
}
to this:
{
"RabbitMq": {
"HostNames": [ "hostname1", "hostname2", "hostname3" ],
"Port": "5672",
"UserName": "guest",
"Password": "guest"
}
}
or this:
{
"RabbitMq": {
"TcpEndpoints": [
{
"HostName": "hostname1",
"Port": 5672
},
{
"HostName": "hostname2",
"Port": 45672
},
{
"HostName": "hostname3",
"Port": 345672
}
],
"Port": "5672",
"UserName": "guest",
"Password": "guest"
}
}
But the last case is suitable only for RabbitMQ nodes not running on default port.
The flow of adding RabbitMQ client will not change and will be the same
services.AddRabbitMqClient(Configuration.GetSection("RabbitMq"))
.AddConsumptionExchange("exchange.name", Configuration.GetSection("RabbitMqExchange"));
You can find those changes in libraries v2.2.1 (for .Net Core 2.2) and v3.1.0 (for .Net Core 3.1) depending on the platform that you are using.
I also wrote an issue about creating detailed wiki https://github.com/AntonyVorontsov/RabbitMQ.Client.Core.DependencyInjection/issues/6 So I am planning to cover those changes in a better way than simply increasing the size of readme file.
Try it out and feel free to write me a review on this!
Regards, Antony
Mohammad, hi!
I added this feature. Now you can connect multiple hosts different ways. So there are three properties in
RabbitMqClientOptions
class now. You can either set one hostname (HostName
property), collection of hostnames (HostNames
property) or collection of endpoints where endpoint is a pair of hostname and port values (TcpEndpoints
property).If you use appsettings.json and, I am completely sure that you do, you can change your configuration from this
{ "RabbitMq": { "HostName": "127.0.0.1", "Port": "5672", "UserName": "guest", "Password": "guest" } }
to this:
{ "RabbitMq": { "HostNames": [ "hostname1", "hostname2", "hostname3" ], "Port": "5672", "UserName": "guest", "Password": "guest" } }
or this:
{ "RabbitMq": { "TcpEndpoints": [ { "HostName": "hostname1", "Port": 5672 }, { "HostName": "hostname2", "Port": 45672 }, { "HostName": "hostname3", "Port": 345672 } ], "Port": "5672", "UserName": "guest", "Password": "guest" } }
But the last case is suitable only for RabbitMQ nodes not running on default port.
The flow of adding RabbitMQ client will not change and will be the same
services.AddRabbitMqClient(Configuration.GetSection("RabbitMq")) .AddConsumptionExchange("exchange.name", Configuration.GetSection("RabbitMqExchange"));
You can find those changes in libraries v2.2.1 (for .Net Core 2.2) and v3.1.0 (for .Net Core 3.1) depending on the platform that you are using.
I also wrote an issue about creating detailed wiki #6 So I am planning to cover those changes in a better way than simply increasing the size of readme file.
Try it out and feel free to write me a review on this!
Regards, Antony
Thank you a lot
Hi Thank you for the library. I set up the RabbitMq Highly Available (Mirrored) policy, how can set multiple hosts in your library? In RabbitMqClientOptions class only I can set one HostName, How can I set multiple hosts?