preface
The last article introduced the implementation of RPC calls with Dubbo + ZooKeeper, do you have any questions?
- Why zK?
- Why do consumers want to configure zK address, what is the role?
- Why does the producer configure the ZK address and what does it do?
Zk is mainly used for data publishing and subscription!!
The Idea of installing zookeeper
- The Idea of the plugin search
Zookeeper plug-in
And restart - Configure the IP address after the restart
The zk analysis
Zk node
- The interior of ZK is composed of nodes, similar to the node concept of binary tree, and each node can exist
Child nodes
andCurrent Node Information
.
Persistent node
Temporary node
Persistent node
- As the name implies, persistent nodes do not disappear when the client is disconnected from the server. The service name node in Dubbo is the persistent node.
Temporary node
- Temporary node when the client is disconnected from the server due to zKheartbeatThe temporary node will be deleted. In the Dubbo
URL configuration node
It’s the persistent node.
Dubbo registers and listens
Producers publish information to ZK
- The producer configates the ZK address in the configuration file, and when the project starts, Dubbo writes node information to the ZK, pushing data to the ZK.
- The directory of the node is: dubbo, service name, provider-URL, etc. The fourth node is a temporary node, which contains IP address, service name, various methods of the service, dubbo version number, time stamps, etc
Consumers subscribe to zK nodes
- Because consumers have
@Refrence
Note that Dubbo listens on the child nodes of the service in ZK for information. - When the producer hangs, zK will delete the temporary node due to the heartbeat mechanism, and when the consumer listens to the information change of the node, the consumer will pull the information of the listening node.
The consumer invokes the producer service
- Consumers get the information and make remote calls through Dubbo’s various protocols.
- When one of the producer’s services is disconnected, ZK actively sends changes to the listener (consumer) for the convenience of the consumer.
- If the provider is disconnected, you can invoke it in direct connection mode.
The problem
- Since consumers are the nodes that listen to producers, what is the purpose of the consumer nodes created by Dubbo in ZK
Guess: Used to givedubbo-admin
And provide consumer information.
At the end
Because che has not seen the source of Dubbo registration subscription, so the above is not guaranteed to be 100% correct ~~~