RabbitMQ Client connect to several hosts

浪子不回头ぞ 提交于 2019-12-06 15:53:50

One way to solve this typical problem is configure an load-balancer (it's enough in roud-robin configuration ) for your cluster (like HAPROXY, cross-road ..or others) .

client(s)--->ip-load-balacer--brokerS

In this way you can use only the load-balancer IP in your client(s) connection.

For having more flexibility you can add a DNS (local dns) bound to the load balancer, in this way you can also change the balancer without change the client configuration.

client(s)--->-load-balacer-DNSNAME--brokerS

If one client lose the connection you have to re-coonect it to the same ip or dns.

You should have an HA client for c# like this for java, or simply manage the connection shutdown event.

Say that, if you have a small and static cluster you could use the IP(s) from the client side.

From the client side (if you want handle only the disconnect):

connection = connection = factory.CreateConnection();
channel = connection.CreateModel();
.......
connection.ConnectionShutdown += Connection_ConnectionShutdown;

 void Connection_ConnectionShutdown(IConnection connection, ShutdownEventArgs reason)
{
    Console.WriteLine("connection_ConnectionShutdown " + reason.ToString());
    Reconnect_client();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!