Eureka是什么?

1、Eureka是SpringCloud Netflix的核心子模块。

2、Eureka包含Eureka Server和Eureka Client。

3、Server提供注册服务,存储所有可用服务节点。

4、用于简化Client与Server通讯复杂度。

 

Eureka原理流程图:

 

Eureka核心特性

一、服务注册(Registry)
(1)Eureka Client在第一次心跳时向Eureka Server注册
(2)注册时会提供诸多自身元数据:主机名、端口、健康指标URL等
二、服务续约(Renew)
(1)Eureka Client通过发送心跳进行续约
(2)默认每30秒发送一次心跳
(3)如果90秒内Eureka Server未收到续约,则进行服务剔除
三、服务下线(Cancel)
(1)Eureka Client优雅退出时会发送cancel命令
(2)Eureka Server收到cancel命令时会删除该节点

 

Eureka为什么注册慢?

Eureka注册慢的根本原因是在于Eureka要保证AP特性

Eureka client 延迟注册,默认30秒

Eureka server的响应缓存,默认30秒

Eureka server的缓存刷新,默认30秒

最极端最慢是90秒

 

Eureka的自我保护

Eureka server会自动更新续约更新阀值

Eureka server续约更新频率低于阀值则进入保护模式

自我保护模式下Eureka server不会剔除任何注册信息

 

Eureka环境搭建:

1、pom文件加以下maven依赖包:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter</artifactId>
            <version>2.2.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-eureka-server</artifactId>
            <version>2.2.2.RELEASE</version>
        </dependency>
    </dependencies>

2、配置文件application.yml加以下配置:

server:
  port: 8761
  tomcat:
    uri-encoding: utf-8

eureka:
  instance:
    hostname: localhost
    # 优先使用IP地址方式进行注册服务
    prefer-ip-address: true
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: http://localhost:${server.port}/eureka/

spring:
  application:
    name: spring-cloud-eureka

3、EurekaApplication.java文件加注解@EnableEurekaServer

启动项目访问http://localhost:8761/

 

 服务注册中心有哪些?

1、Eureka

2、Zookeeper

3、Consul

4、Nacos

 

Eureka示例项目代码github地址:https://github.com/yuanzipeng/spring-cloud-eureka master分支

Eureka控制台参数说明:https://www.cnblogs.com/yuanzipeng/p/13054089.html

spring Cloud服务注册中心Eureka集群:https://www.cnblogs.com/yuanzipeng/p/13054508.html

 

posted on 2020-06-06 10:44  袁子弹  阅读(329)  评论(0编辑  收藏  举报