Netty 旋转重新连接处理程序
我正在尝试在 netty 中编写一个处理程序,其中包含 n 个 SocketAddress 列表。我想要发生的事情是从第一个地址开始并尝试连接。如果失败,请尝试下一个地址,依此类推。
如果连接因任何原因断开,那么我希望无限期地重试连接,并在地址列表中轮换。
有人对如何写这篇文章有任何建议吗?我找到了有关执行单个地址重新连接处理程序的网络示例,但不确定多个情况。
I am trying to write a handler in netty which holds a list of n SocketAddress
. What I would like to happen is start with the first address and try to connect. If this fails, try the next address and so on.
If the connection drops for any reason then I would like the connection to be retried indefinitely, rotating through the address list.
Does anyone have any suggestions about how to go about writing this. I have found the netty example about doing a single address reconnect handler but not sure about the multiple case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可以使用 ChannelFutureListener 作为连接部分轻松完成此操作。对于连接丢失,您可以编写自定义的 SimpleUpstreamChannelHandler 并重写 connectionClosed(..) 方法来处理“重新连接”。
I thin you could do this easily with a ChannelFutureListener for the connection part. For the connection drop you could write your custom SimpleUpstreamChannelHandler and override the connectionClosed(..) method to handle the "reconnect".