In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
How to understand the expiration of zookeeper session? in view of this problem, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
Explanation of session expiration in zookeeper:
When client and server are connected, there is no 100% guarantee that they will always be connected. Such as network problems. Then client needs to reconnect, and the implementation of this mechanism is complicated, and there is still a Curator client to help us solve it. We only need to register a listener after the connection.
If the analog server line is not available, you can turn on the firewall method, or
Open port 81:
Iptables-I INPUT-I eth0-p tcp-- dport 81-j ACCEPT
Iptables-I OUTPUT-o eth0-p tcp-- sport 81-j ACCEPT
Shut down port 81:
Iptables-I INPUT-I eth0-p tcp-- dport 81-j DROP
Iptables-I OUTPUT-o eth0-p tcp-- sport 81-j DROP
And then save.
The specific code is as follows:
The code is as follows:
String path = "/ session/service-"; SessionConnectionStateListener listener = new SessionConnectionStateListener (path,zookeeperConnectionString); client.getConnectionStateListenable () .addListener (listener); client.create () .creatingParentsIfNeeded () .withMode (CreateMode.EPHEMERAL_SEQUENTIAL) .forPath (path, "" .getBytes ())
Here is the listener:
Package com.mmblue.demo;import org.apache.curator.framework.CuratorFramework;import org.apache.curator.framework.state.ConnectionState;import org.apache.curator.framework.state.ConnectionStateListener;import org.apache.zookeeper.CreateMode;public class SessionConnectionStateListener implements ConnectionStateListener {private String zkRegPathPrefix; private String regContent; public SessionConnectionStateListener (String zkRegPathPrefix, String regContent) {this.zkRegPathPrefix = zkRegPathPrefix; this.regContent = regContent } @ Override public void stateChanged (CuratorFramework curatorFramework, ConnectionState connectionState) {if (connectionState = = ConnectionState.LOST) {while (true) {try {System.err.println ("I'm coming, hey") If (curatorFramework.getZookeeperClient () .blockUntilConnectedOrTimedOut ()) {curatorFramework.create () .creatingParentsIfNeeded () .withMode (CreateMode.EPHEMERAL_SEQUENTIAL) .forPath (zkRegPathPrefix, regContent.getBytes ("UTF-8")); break }} catch (InterruptedException e) {break } catch (Exception e) {}} this is the answer to the question about how to understand the expiration of zookeeper session. I hope the above content can help you to a certain extent, if you still have a lot of doubts to be solved, you can follow the industry information channel to learn more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.