SpringCloud03-Zookeeper
1.Zookeeper
- 待更新......
2.下载、安装和运行
- 下载地址。https://zookeeper.apache.org/releases.html;SpringCloud社区地址,https://docs.spring.io/spring-cloud-zookeeper/docs/current/reference/html/。
- 下载完成直接解压就可以使用。
- 运行。Windows下,直接在bin下双击运行zkServer.cmd,然后双击运行客户端程序,zkCli.cmd。
- 在Zookeeper客户端查看Zookeeper节点信息的命令。
# 查看/节点
ls /
# 查看所有的服务
ls /servers
# 查看具体服务的实例信息
ls /services/cloud-provider-payment
# 查看服务的具体实例信息
get /services/cloud-provider-payment/f17b3f59-284c-43df-85dc-17fcb686466c
3.创建Zookeeper客户端微服务cloud-zookeeper-provider-payment8004
- pom.xml
<!-- zookeeper客户端依赖,其他依赖桶Eureka客户端依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
</dependency>
- yml
server:
port: 8004
spring:
application:
name: cloud-provider-payment
cloud:
zookeeper:
connect-string: 127.0.0.1:2181
- Main
// 将当前服务注册到Zookeeper的注册中心
@EnableDiscoveryClient
@SpringBootApplication
public class CloudZookeeperProviderPayment8004Main {
public static void main(String[] args) {
SpringApplication.run(CloudZookeeperProviderPayment8004Main.class, args);
}
}
4.创建Zookeeper客户端微服务cloud-zookeeper-consumer-order80
- pom.xml、yml、Main同上。
- 说明,spring-cloud-starter-zookeeper-discovery引人了spring-cloud-starter-loadbalance进行负载均衡。