马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
前言
1:对于能提供完备范畴服务接口功能的RPC而言,比方;gRPC、Thrift、Dubbo等,服务的注册与发现都是焦点功能中非常紧张的一环,使得微服务得到同一管理。
2:在分布式范畴中有个闻名的CAP理论;同等性(Consistency)、可用性(Availability)、分区容错性(Partition tolerance),这三个要素在分布式体系中,最多满意两个,不大概三者分身。
3:通常我们在使用dubbo时zookeeper作为注册中央以选主设置为焦点,包管CP特性,即任何时间对 Zookeeper 的访问哀求能得到同等的数据结果,同时体系对网络分割具备容错性,但是它不能包管每次服务哀求的可用性。
4:而 Spring Cloud Netflix 在计划 Eureka 时服从的就是 AP 原则,由于对于服务发现而言,可用性比数据同等性显得尤为紧张。
案例阐明
案列使用版本如下
1:jdk 1.8
2:Spring Boot 2.0.6.RELEASE
3:Spring Cloud Finchley.SR2
新建应用启动类
EurekaServerApplication.java | 三组node代码同等,只须要一个平凡的springboot添加@EnableEurekaServer即可启动- @SpringBootApplication
- @EnableEurekaServer
- public class EurekaServerApplication {
- public static void main(String[] args) {
- SpringApplication.run( EurekaServerApplication.class, args );
- }
- }
复制代码 application.yml | node1 指向别的两台服务,registerWithEureka、fetchRegistry和单实例差异须要设置为true- spring:
- application:
- name: demo-eureka-server
- server:
- port: 8081
- eureka:
- instance:
- hostname: node01
- client:
- registerWithEureka: true
- fetchRegistry: true
- serviceUrl:
- defaultZone: http://node02:8082/eureka/,http://node03:8083/eureka/
复制代码 application.yml | node2 指向别的两台服务- spring:
- application:
- name: demo-eureka-server
- server:
- port: 8082
- eureka:
- instance:
- hostname: node02
- client:
- registerWithEureka: true
- fetchRegistry: true
- serviceUrl:
- defaultZone: http://node03:8083/eureka/,http://node01:8081/eureka/
复制代码 application.yml | node3 指向别的两台服务- spring:
- application:
- name: demo-eureka-server
- server:
- port: 8083
- eureka:
- instance:
- hostname: node03
- client:
- registerWithEureka: true
- fetchRegistry: true
- serviceUrl:
- defaultZone: http://node01:8081/eureka/,http://node02:8082/eureka/
复制代码 测试验证
1:设置host;127.0.0.1 node01 node02 node03
2:分别启动node1、node2、node3
3:访问;http://localhost:8081/
好了到这里就竣事了一偏概述告诉你SpringCloud是什么的学习,各人肯定要跟着动手使用起来。须要源码的 可si我获取;
|