springcloud之服务集群注册与发现 Eureka

前言

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即可启动

java 复制代码
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

    public static void main(String[] args) {
        SpringApplication.run( EurekaServerApplication.class, args );
    }

}

application.yml | node1 指向另外两台服务,registerWithEureka、fetchRegistry和单实例不同需要配置为true

yaml 复制代码
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 指向另外两台服务

yaml 复制代码
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 指向另外两台服务

yaml 复制代码
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我获取;

相关推荐
晚霞的不甘25 分钟前
CANN 编译器深度解析:UB、L1 与 Global Memory 的协同调度机制
java·后端·spring·架构·音视频
寄存器漫游者2 小时前
Linux 软件编程 - IO 编程
linux·运维·spring
我真会写代码2 小时前
SSM(指南一)---Maven项目管理从入门到精通|高质量实操指南
java·spring·tomcat·maven·ssm
vx_Biye_Design2 小时前
【关注可免费领取源码】房屋出租系统的设计与实现--毕设附源码40805
java·spring boot·spring·spring cloud·servlet·eclipse·课程设计
独断万古他化5 小时前
【SSM开发实战:博客系统】(三)核心业务功能开发与安全加密实现
spring boot·spring·mybatis·博客系统·加密
若鱼19195 小时前
SpringBoot4.0新特性-Observability让生产环境更易于观测
java·spring
Volunteer Technology6 小时前
sentinel基本操作
spring cloud·sentinel
Dragon Wu6 小时前
Spring Security Oauth2.1 授权码模式实现前后端分离的方案
java·spring boot·后端·spring cloud·springboot·springcloud
跳动的梦想家h6 小时前
环境配置 + AI 提效双管齐下
java·vue.js·spring
Zfox_6 小时前
CANN Catlass 算子模板库深度解析:高性能 GEMM 融合计算、Cube Unit Tiling 机制与编程范式实践
docker·云原生·容器·eureka