1.安装zookeeper
https://blog.csdn.net/ring300/article/details/80446918
2.创建 提供者 02-provider-zk
1.1 导入依赖
复制前面的提供者工程 01-provider,并更名为 02-provider-zk。修改 pom 文件,并在其中导入 Zookeeper 客户端依赖 curator
<!-- zk客户端依赖:curator -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>2.13.0</version>
</dependency>
1.2 改修改 spring 配置文件
<dubbo:application name="02-provider-zk"/>
<!--声明注册中心:单机版zk-->
<dubbo:registry address="zookeeper://zkOS:2181"/>
<!--<dubbo:registry protocol="zookeeper" address="zkOS:2181"/>-->
<!--声明注册中心:zk群集-->
<!--<dubbo:registry address="zookeeper://zkOS1:2181?backup=zkOS2:2181,zkOS3:2181,zkOS4:2181"/>-->
<!--<dubbo:registry protocol="zookeeper" address="zkOS1:2181,zkOS2:2181,zkOS3:2181,zkOS4:2181"/>-->
<bean id="someService" class="com.abc.provider.SomeServiceImpl"/>
<dubbo:service interface="com.abc.service.SomeService" ref="someService" />
3.创建消费者 02-consumer-zk
2.1 导入依赖
复制前面的消费者工程 01-consumer,并更名为 02-consumer-zk。修改 pom 文件,并在其中导入 Zookeeper 客户端 curator 依赖。
<!-- zk客户端依赖:curator -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>2.13.0</version>
</dependency>
2.2 修改 spring 配置文件
<dubbo:application name="02-consumer-zk">
<dubbo:parameter key="qos.port" value="33333"/>
</dubbo:application>
<!--指定服务注册中心:zk单机-->
<dubbo:registry address="zookeeper://zkOS:2181" />
<!--<dubbo:registry protocol="zookeeper" address="zkOS:2181"/>-->
<!--指定服务注册中心:zk集群-->
<!--<dubbo:registry address="zookeeper://zkOS1:2181?backup=zkOS2:2181,zkOS3:2181,zkOS4:2181"/>-->
<!--<dubbo:registry protocol="zookeeper" address="zkOS1:2181,zkOS2:2181,zkOS3:2181,zkOS4:2181"/>-->
<dubbo:reference id="someService" check="false" interface="com.abc.service.SomeService"/>