Spring Cloud
  • Introduction
  • 网站架构演变过程
    • 微服务架构
  • Spring Cloud 简介
  • 服务的注册与发现
    • 其他知识
      • Zookeeper与Eureka区别
      • DiscoveryClient 与@EnableEurekaServer
    • Zookeeper
    • Consul
    • Eureka
      • 搭建注册中心
      • 高可用注册中心
      • Eureka详解
  • 服务消费者
    • RestTemplate
    • 服务消费者(rest+ribbon)
      • 此时架构
    • 服务消费者(Feign)
  • 断路器(Hystrix)
    • 基础入门
  • API Gateway(Zuul)
    • 基础入门
  • 分布式配置中心(Config)
    • 基础入门
  • SpringCloud Bus
  • 链路跟踪(Sleuth)
  • 数据流(Stream)
  • Dubbo
    • Untitled
Powered by GitBook
On this page
  • Zookeeper简介
  • 环境搭建
  • 启动zk服务器端
  • Maven依赖信息
  • application.yml
  • 会员配置文件
  • 订单配置文件
  • 处理错误

Was this helpful?

  1. 服务的注册与发现

Zookeeper

PreviousDiscoveryClient 与@EnableEurekaServerNextConsul

Last updated 4 years ago

Was this helpful?

Zookeeper简介

Zookeeper是一个分布式协调工具,可以实现服务注册与发现、注册中心、消息中间件、分布式配置中心等。

Zookeeper 分布式协调工具,可以实现注册中心,采用Zookeeper节点类型? 用的临时节点

临时节点和生命周期进行关联的。

Zookeeper 没有像Ereka那样有自动保护机制,

如果服务断开连接之后,该节点会自动的被删除掉。

环境搭建

docker run -d -p 2181:2181 --name some-zookeeper --restart always zookeeper

启动zk服务器端

Maven依赖信息


	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.1.RELEASE</version>
	</parent>
	<!-- 管理依赖 -->
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>Finchley.M7</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>
	<dependencies>
		<!-- SpringBoot整合Web组件 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<!-- SpringBoot整合eureka客户端 -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
		</dependency>

	</dependencies>
	<!-- 注意: 这里必须要添加, 否者各种依赖有问题 -->
	<repositories>
		<repository>
			<id>spring-milestones</id>
			<name>Spring Milestones</name>
			<url>https://repo.spring.io/libs-milestone</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>

application.yml

会员配置文件

###订单服务的端口号
server:
  port: 8002
###服务别名----服务注册到注册中心名称 
spring:
  application:
    name: zk-member
  cloud:
    zookeeper:
      connect-string: 127.0.0.1:2181

订单配置文件

###订单服务的端口号
server:
  port: 8003
###服务别名----服务注册到注册中心名称 
spring:
  application:
    name: zk-order
  cloud:
    zookeeper:
      connect-string: 127.0.0.1:2181

启动zk-member服务和zk-order服务,可以发现在Zk服务器端上有对应的节点信息

别忘记加入注释

@EnableDiscoveryClient

处理错误

Docker下安装zookeeper(单机 & 集群)
ZookeeperProviderApplicationTests.contextLoads » IllegalState Failed to load A...