微服务化是当前一大趋势,注册中心则是微服务最基础的组件,是以前组内安排的任务,因而把结果分享出来,本文对当前业界比较流行的微服务组件进行了调研,并做出了总结。web
当前对微服务组件的调研维度以下:社区生态热度、易用性、性能、cap分布式特性、当前组件维护状态、重点功能等。spring
server配置bootstrap
pom引用
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
yml配置
eureka:
instance:
hostname: localhost
instance-id: localhost:${server.port}
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
server:
renewalPercentThreshold: 0.49
renewalThresholdUpdateIntervalMs: 180000 # 3mins
#peerEurekaNodesUpdateIntervalMs: 500
复制代码
springbootapplication启动类加入@EnableEurekaServer缓存
client配置springboot
pom引用
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
yml配置
eureka:
client:
service-url:
defaultZone: http://localhost:10001/eureka
复制代码
springbootapplication启动类加入@EnableEurekaServer,直接启动server便可。bash
server配置:app
server下载安装,并启动, unzip nacos-server-version.tar.gz分布式
cd nacos/binide
sh startup.sh -m standalone微服务
client配置:
pom引用
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>0.9.0.RELEASE</version>
</dependency>
yml配置
spring:
application:
name: nacos-demo
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
management:
endpoints:
web:
exposure:
include: '*'
复制代码
springbootapplication启动类加入@EnableEurekaClient。
server配置:
官方地址下载,而且启动
以单节点启动 consul agent -advertise 127.0.0.1 -data-dir=/tmp/consul -server -bootstrap
client配置
pom引用
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
yml配置
spring:
application:
name: consul-provider
cloud:
consul:
host: 127.0.0.1
port: 8500
discovery:
register: true
service-name: consul-provider
复制代码
springbootapplication启动类加入@EnableEurekaClient。
维度 | eureka | nacos | consul |
---|---|---|---|
社区生态 | 社区热度高 | 社区热度较低、中文文档多 | 社区热度较高 |
性能 | 8核16G服务端定时轮询查询更新,当服务数量过多(8000-10000)时,压力过大 | 8核16G单个节点9000以上的链接时会出现硬件负载太高场景 | 暂无 |
cap分布式特性 | AP可用性以及分区容错性;可用性:无主从节点,一个节点挂了自动切换其余节点,但可能会致使不一样的注册中心节点的服务列表不一致,能够接受 | AP或CP | CP:做为分布式集群来讲,是CP |
维护状态 | 1.X中止维护;2.0版本闭源 | 近期才开源;只到0.9.0.release; | 一直在跟着spring cloud维护,目前到2.1.1 |
重点功能,特色 | 1.springcloud-starter服务,开箱即用2.有控制台 | 一、支持springcloud 服务发现、配置管理二、有web ui控制台三、经过了大规模的性能测试四、注册中心与配置中心 | 有控制台;缺点:暂时没有对consul集群的配置方式,即服务没法注册多个consul节点 |
注册使用 | service 注册时向eureka server发送自身服务信息;service每30秒向eureka server续约服务;service 每30秒拉取服务列表至本地缓存。 | 一样是使用服务不断上报心跳的方式保持在注册中心的活跃性;服务发现。1、不断从服务端查询可用服务实例。2、从已变服务队列中通知服务持有者的查询任务,服务发生变动时更新本地服务列表。 | 既支持consul主动检查服务的状况,也支持服务主动向consul发送心跳报告本身的健康情况。 |
其余 | k8s集成,dubbo集成均支持 |
eureka、nacos、consul均能支持微服务注册及web ui控制台的最基础的需求,但eureka当前中止开源、consul暂时不支持client配置注册中心集群,按需选择。