Skip to main content

dawdler-discovery-center-zookeeper-core

Module Introduction​

The core module of the ZooKeeper-based registry implementation. It provides a singleton class for ZooKeeper operations and the implementation class for health checking.

1. Configuration Files​

A local configuration file or a unified configuration center is supported.

1.1 Local Configuration File​

The zookeeper.properties file is located on the project classpath. If there is no username and password, user and password need not be configured.

connectString=192.168.43.137:2181
#user=zkUser
#password=zkPassword
#baseSleepTimeMs=1000
#maxRetries=3
#reVerifyInterval=30

1.2 Unified Configuration Center​

For the unified configuration center, see the Unified Configuration Center module

The path inside consul is /zookeeper

connectString:192.168.43.137:2181

1.3 Configuration Parameter Description​

connectString: the connection address of ZooKeeper; multiple addresses are separated by commas.

user: the authentication username for ZooKeeper. It need not be set if it is not configured.

password: the authentication password for ZooKeeper. It need not be set if it is not configured.

baseSleepTimeMs: the initial retry wait time in milliseconds, default 1000.

maxRetries: the maximum number of retries, default 3.

reVerifyInterval: the registration self-verification interval in seconds, default 30. At this interval the server side checks whether the locally registered node still exists, and if not, re-registers it with the original data. If the check throws an exception, it only marks the registry as unstable and logs it, then tries again in the next cycle.

2. Subscription, Reconciliation and Self-Protection​

Consumer-side instances are maintained uniformly by ZkServiceSubscriber: CuratorCache node events (with 200 ms debouncing) and periodic reconciliation (default 60 seconds, adjustable via reconcileInterval in discovery-center.properties) write into the single JVM-wide ServiceInstanceCache. Server-side registration self-healing has two entry points: idempotently rebuilding EPHEMERAL nodes in the registry after a reconnect, and registration self-verification every 30 seconds (reVerifyInterval); the latter covers cases such as the reconnect compensation not being executed after a session expires, ZooKeeper being unreachable at startup, and nodes being mistakenly deleted at runtime.

The node path /dawdler/{service}/{host:port} remains unchanged, while the node data changes from the host:port bytes to ServiceInstance JSON; old-format data is automatically downgraded to a default instance, so old and new versions can be deployed together.

When the ZooKeeper connection is SUSPENDED/LOST/RECONNECTED, the consumer cache enters self-protection mode (see the core module README) to suppress erroneous batch deregistration; after RECONNECTED, the full RESYNC is subject to the same self-protection constraints as node events -- if the RESYNC result is healthy, the unstable window is cleared and protection ends early; if the capacity shrinks sharply, it is still merged by protection, and changes take effect directly once the window expires. getServiceList is retained as a compatibility adapter (it reads ServiceInstanceCache, and falls through to a direct query when there is no cache entry).