如何以编程方式检测集成客户端中的哪个服务器连接?

编程入门 行业动态 更新时间:2024-10-28 06:22:43
本文介绍了如何以编程方式检测集成客户端中的哪个服务器连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

如何以编程方式检测客户端连接到 ZooKeeper 集合中的哪个服务器?

How to programmatically detect which server in a ZooKeeper ensemble a client is connected to?

我正在使用 Apache Curator API,我正在通过注册 ConnectionStateListener.如果客户端连接的服务器出现故障,我想知道当客户端重新连接时客户端连接到整体中的哪个服务器.

I'm using the Apache Curator API and I am listening for state changes in connection by registering ConnectionStateListener. I would like to know which server in the ensemble a client is connected to when the client reconnects if the server it was connected to goes down.

推荐答案

您可以在 Curator 生成的日志中看到这一点.在下面的示例输出中,CuratorFramework 客户端在它可以连接的 connectionString 中获得了 4 个不同的 ZooKeeper 实例.从日志中可以看出,它选择了第一个:

You can see this in the logs produced by Curator. In the example output below, the CuratorFramework client has been given 4 different ZooKeeper instances in the connectionString that it can connect to. As can be seen in the log, it choses the first:

21:13:45.384 [main] INFO  org.apache.curator.framework.imps.CuratorFrameworkImpl - Starting
21:13:45.386 [main] INFO  org.apache.zookeeper.ZooKeeper - Initiating client connection, connectString=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183,127.0.0.1:2184 sessionTimeout=60000 watcher=org.apache.curator.ConnectionState@2876f0c
21:13:45.388 [main-SendThread(127.0.0.1:2181)] INFO  org.apache.zookeeper.ClientCnxn - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
21:13:45.388 [main-SendThread(127.0.0.1:2181)] INFO  org.apache.zookeeper.ClientCnxn - Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session
21:13:45.392 [main-SendThread(127.0.0.1:2181)] INFO  org.apache.zookeeper.ClientCnxn - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x14aac461eb70004, negotiated timeout = 40000

如果客户端连接的 ZooKeeper 服务器崩溃,您还会在日志中看到客户端连接的新服务器:

In case the ZooKeeper server that the client has connected to crashes, you will also see the new server that the client connects to in the logs:

21:23:03.675 [main-SendThread(127.0.0.1:2182)] INFO  org.apache.zookeeper.ClientCnxn - Opening socket connection to server 127.0.0.1/127.0.0.1:2182. Will not attempt to authenticate using SASL (unknown error)
21:23:03.677 [main-SendThread(127.0.0.1:2182)] INFO  org.apache.zookeeper.ClientCnxn - Socket connection established to 127.0.0.1/127.0.0.1:2182, initiating session
21:23:03.697 [main-SendThread(127.0.0.1:2182)] INFO  org.apache.zookeeper.ClientCnxn - Session establishment complete on server 127.0.0.1/127.0.0.1:2182, sessionid = 0x14aac461eb70004, negotiated timeout = 40000
21:23:03.697 [main-EventThread] INFO  org.apache.curator.framework.state.ConnectionStateManager - State change: RECONNECTED

这篇关于如何以编程方式检测集成客户端中的哪个服务器连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-18 17:45:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/943602.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:客户端   方式   服务器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!