Application of Zookeeper in Dubbo

Quoted from: http://www.cnblogs.com/binyue/p/4759734.html

Dubbo's Architecture

Node role description:

Provider: The service provider that exposes the service.
Consumer: The service consumer that invokes the remote service.
Registry: A registry for service registration and discovery.
Monitor: The monitoring center that counts the invocation times and invocation time of the service.
Container: The service runs the container.
Description of the calling relationship:

0. The service container is responsible for starting, loading, and running the service provider.
1. When the service provider starts, it registers the service it provides with the registry.
2. When the service consumer starts, it subscribes to the registration center for the services it needs.
3. The registry returns the service provider address list to the consumer. If there is a change, the registry will push the change data to the consumer based on the persistent connection.
4. The service consumer, from the provider address list, selects a provider to call based on the soft load balancing algorithm, and if the call fails, select another provider to call.
5. Service consumers and providers accumulate the number of calls and call time in the memory, and regularly send statistical data to the monitoring center every minute.

Dubbo recommends using the Zookeeper registry

Flow Description:

When the service provider starts,
it writes its own URL address to the /dubbo/com.foo.BarService/providers directory.
When the service consumer starts, it
subscribes to the provider URL address in the /dubbo/com.foo.BarService/providers directory.
And write your own URL address to the /dubbo/com.foo.BarService/consumers directory.
When the monitoring center starts, it
subscribes to all provider and consumer URL addresses in the /dubbo/com.foo.BarService directory.

The following features are supported:

When the provider experiences abnormal shutdown such as power failure, the registration center can automatically delete the provider information.
When the registry is restarted, the registration data and subscription requests can be automatically restored.
When the session expires, registration data and subscription requests can be automatically restored.
When <dubbo:registry check="false" /> is set, failed registration and subscription requests are recorded, and the background is retried regularly.
The zookeeper login information can be set through <dubbo:registry username="admin" password="1234" />.
The root node of zookeeper can be set through <dubbo:registry group="dubbo" />, if not set, an unrooted tree will be used.
The * wildcard <dubbo:reference group="*" version="*" /> is supported to subscribe to all groups and all version providers of the service.

Add zookeeper client jar package dependencies in provider and consumer:

1
2
3
4
5
< dependency >
< groupId >org.apache.zookeeper</ groupId >
< artifactId >zookeeper</ artifactId >
< version >3.3.3</ version >
</ dependency >

  

Or download directly: http://repo1.maven.org/maven2/org/apache/zookeeper/zookeeper

zkclient client implementation:

ZKClient Zookeeper Registry

Since version 2.2.0, the default is zkclient implementation to improve the robustness of zookeeper client.

ZKClient is a Zookeeper client implementation open sourced by Datameer. Open source is relatively early. See: https://github.com/sgroschupf/zkclient

Default configuration:

<dubbo:registry ... client="zkclient" />

or:

dubbo.registry.client=zkclient

or:

zookeeper://10.20.153.10:2181?client=zkclient

Depends on:

1
2
3
4
5
< dependency >
< groupId >com.github.sgroschupf</ groupId >
< artifactId >zkclient</ artifactId >
< version >0.1</ version >
</ dependency >

  

Or download directly: http://repo1.maven.org/maven2/com/github/sgroschupf/zkclient

Zookeeper stand-alone configuration:

1
2
3
< dubbo:registry address="zookeeper://10.20.153.10:2181" />
Or:
< dubbo:registry protocol="zookeeper" address="10.20.153.10:2181" />

  

Zookeeper cluster configuration:

1
2
3
< dubbo:registry address="zookeeper://10.20.153.10:2181?backup=10.20.153.11:2181,10.20.153.12:2181" />
Or:
< dubbo:registry protocol="zookeeper" address="10.20.153.10:2181,10.20.153.11:2181,10.20.153.12:2181" />

  

The same Zookeeper is divided into multiple groups of registration centers:

1
2
< dubbo:registry id="chinaRegistry" protocol="zookeeper" address="10.20.153.10:2181" group="china" />
< dubbo:registry id="intlRegistry" protocol="zookeeper" address="10.20.153.10:2181" group="intl" />

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326484330&siteId=291194637