preface

The last article introduced the implementation of RPC calls with Dubbo + ZooKeeper, do you have any questions?

  1. Why zK?
  2. Why do consumers want to configure zK address, what is the role?
  3. 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

  1. The Idea of the plugin searchZookeeper plug-inAnd restart
  2. Configure the IP address after the restart

The zk analysis

Zk node

  1. The interior of ZK is composed of nodes, similar to the node concept of binary tree, and each node can existChild nodesandCurrent Node Information.

Persistent node
Temporary node

Persistent node

  1. 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

  1. Temporary node when the client is disconnected from the server due to zKheartbeatThe temporary node will be deleted. In the DubboURL configuration nodeIt’s the persistent node.

Dubbo registers and listens

Producers publish information to ZK

  1. 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.
  2. 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

  1. Because consumers have@RefrenceNote that Dubbo listens on the child nodes of the service in ZK for information.
  2. 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

  1. Consumers get the information and make remote calls through Dubbo’s various protocols.
  2. When one of the producer’s services is disconnected, ZK actively sends changes to the listener (consumer) for the convenience of the consumer.
  3. If the provider is disconnected, you can invoke it in direct connection mode.

The problem

  1. 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-adminAnd 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 ~~~