zookeeper(4)注册中心
2019-10-13 17:08
330 查看
案例
注册中心可以使用Eureka来实现,这个比较简单,可以看之前的例子spring-cloud。
那么使用zookeeper如何来实现注册中心呢?
基于spring cloud我们也可以非常简单的实现。
1、利用之前搭建的zookeeper集群,zookeeper集群
2、新建maven工程
1、POM文件如下:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <modelVersion>4.0.0</modelVersion> <groupId>com.jane</groupId> <artifactId>zookeeper-register-server</artifactId> <version>1.0-SNAPSHOT</version> <properties> <java.version>1.8</java.version> <spring-cloud.version>Greenwich.SR1</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> 5b28 </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
2、启动文件如下:
package com.jane.zk; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @SpringBootApplication @EnableCaching @EnableDiscoveryClient public class OrderServiceApplication { public static void main(String[] args) { SpringApplication.run(OrderServiceApplication.class, args); } }
3、配置文件如下:
spring.application.name=order-service management.endpoints.web.exposure.include=* management.endpoint.health.show-details=always server.port=0 spring.cloud.zookeeper.connect-string=www.****.com:2181,www.*****.club:2181,www.*****.club:2181
启动之后,查看zookeeper的节点
1、服务节点都位于目录services下:
2、services目录下有对应的服务节点
3、查看服务节点对应的节点信息
至此,一个服务就成功注册到了zookeeper上了。
相关文章推荐
- zookeeper作为注册中心,使用dubbo
- 使用Zookeeper作为注册中心和配置中心
- ZooKeeper 集群的安装、配置---Dubbo 注册中心
- Spring Cloud使用zookeeper作为服务注册中心与配置中心
- dubbo分布式服务 (三) 注册中心zookeeper集群安装
- 安装Dubbo注册中心(Zookeeper-3.4.6)
- 基于Dubbo的分布式系统架构(一):安装ZooKeeper注册中心(单机版)
- Zookeeper最常用的作用,作为dubbo的注册中心
- 基于ZooKeeper的Dubbo注册中心
- linux 搭建zookeeper注册中心(集群)
- 跟我学习dubbo-ZooKeeper注册中心安装(2)
- Dubbo-----HelloWorld之Zookeeper注册中心(2)
- Dubbo的高可用,如果作为注册中心的zookeeper宕机了,那消费者是否还能调用提供者的服务呢?
- 选 Zookeeper 作为注册中心我们还要注意些什么
- dubbo(分布式架构)+zookeeper(注册中心)+spring(provider和consumer) 基本使用
- Dubbo-Admin管理平台和Zookeeper注册中心的搭建
- 阿里dubbo框架使用系列:开发环境搭建之zookeeper注册中心(单节点)
- Dubbo框架应用之(三)--Zookeeper注册中心、管理控制台的安装及讲解
- Zookeeper 注册中心安装
- Dubbo框架结合Zookeeper注册中心使用