服务的注册与发现(Eureka)二:环境搭建

  简介

            Eureka 是一个基于 REST 的服务,主要在 AWS 云中使用, 定位服务来进行中间层服务器的负载均衡和故障转移。

Eureka工作原理

        Spring Cloud 封装了 Netflix 公司开发的 Eureka 模块来实现服务注册和发现。Eureka 采用了 C-S 的设计架构。Eureka Server 作为服务注册功能的服务器,它是服务注册中心。而系统中的其他微服务,使用 Eureka 的客户端连接到 Eureka Server,并维持心跳连接。这样系统的维护人员就可以通过 Eureka Server 来监控系统中各个微服务是否正常运行。Spring Cloud 的一些其他模块(比如Zuul)就可以通过 Eureka Server 来发现系统中的其他微服务,并执行相关的逻辑。

 
       Eureka由两个组件组成:Eureka服务器和Eureka客户端。Eureka服务器用作服务注册服务器。Eureka客户端是一个java客户端,用来简化与服务器的交互、作为轮询负载均衡器,并提供服务的故障切换支持。Netflix在其生产环境中使用的是另外的客户端,它提供基于流量、资源利用率以及出错状态的加权负载均衡。

用一张图来认识以下:

上图简要描述了Eureka的基本架构,由3个角色组成:

Eureka  Server

  •    提供服务注册和发现

Service  Provider

  •    服务提供方,将自身服务注册到Eureka,从而使服务消费方能够找到

Service  Consumer

  •    服务消费方,从Eureka获取注册服务列表,从而能够消费服务

案例搭建

示例代码

建立spring-cloud-examples主工程项目

主工程Maven依赖信息

该依赖作为往后案例的主依赖

<?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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>net.riking</groupId>
    <artifactId>spring-cloud-examples</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>eureka-provider-consumer</module>
        <module>eureka-cluster-provider-consumer</module>
        <module>ribbon-provider-consumer</module>
        <module>hystrix-dashboard-turbine</module>
        <module>config-bus-server</module>
        <module>feign-client</module>
    </modules>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <junit.version>4.12</junit.version>
        <log4j.version>1.2.17</log4j.version>
        <lombok.version>1.18.8</lombok.version>
    </properties>

    <!-- 管理依赖 -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.M7</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <!--使用 lombok 简化 Java 代码-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <!-- 注意: 这里必须要添加, 否者各种依赖有问题 -->
    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/libs-milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

</project>
pom.XML

建立eureka-provider-consumer 子工程

服务注册中心

Maven依赖信息

    <dependencies>
        <!--SpringCloud eureka-server -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>

application.yml 配置文件

###服务端口号
server:
  port: 7001
###eureka 基本信息配置
eureka:
  instance:
    ###注册到eurekaip地址
    hostname: localhost
  client:
    serviceUrl:
      #设置与Eureka Server交互的地址查询服务和注册服务都需要依赖这个地址(单机)。
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
    ###因为自己是为注册中心,不需要自己注册自己
    register-with-eureka: false
    ###因为自己是为注册中心,不需要检索服务
    fetch-registry: false

启动Eureka服务

package net.riking.springcloud.eureka;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplication
public class AppEureka {

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

}

启动工程后,访问:http://localhost:7001/,可以看到下面的页面,其中还没有发现任何服务

服务提供方

Maven依赖信息

    <dependencies>
        <!-- SpringBoot整合Web组件 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- SpringBoot整合eureka客户端 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
    </dependencies>

application.yml 配置文件

#服务启动端口号
server:
  port: 8001

#服务名称(服务注册到eureka名称)
spring:
  application:
    name: provider

#客户端注册进eureka服务列表内
eureka:
  client:
    service-url:
      defaultZone: http://localhost:7001/eureka
    #该应用为注册中心,不会注册自己,默认true
    register-with-eureka: true
    #是否需要从eureka上获取注册信息,默认true
    fetch-registry: true

 

服务接口

package net.riking.springcloud.provider.controller;

import net.riking.springcloud.provider.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user/provider")
public class UserProviderController {

    @GetMapping
    public User provider(@RequestParam String username) {
        User user = new User();
        user.setUsername(username);
        user.setPassword("provider-eureka7001");
        user.setDescription("注册服务提供者");
        return  user ;
    }
}

启动提供服务

package net.riking.springcloud.provider;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@SpringBootApplication
@EnableEurekaClient
public class AppUser {
    public static void main(String[] args) {
        SpringApplication.run(AppUser.class, args);
    }

}

启动工程后,访问:http://localhost:7001/,可以看到下面的页面中提供者已经注册到eureka服务上

 访问:http://localhost:8001/user/provider?username=提供者,可以看到下面的页面中信息输出

服务消费方

Maven依赖信息

  <dependencies>
        <!-- SpringBoot整合Web组件 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- SpringBoot整合eureka客户端 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
    </dependencies>

application.yml 配置文件

#服务启动端口号
server:
  port: 9001

#服务名称(服务注册到eureka名称)
spring:
  application:
    name: consumer
#客户端注册进eureka服务列表内
eureka:
  client:
    service-url:
      defaultZone: http://localhost:7001/eureka
    #该应用为注册中心,不会注册自己,默认true
    register-with-eureka: true
    #是否需要从eureka上获取注册信息,默认true
    fetch-registry: true

使用rest方式调用服务

package net.riking.springcloud.consumer.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/user/consumer")
public class UserConsumerController {
    @Autowired
    private RestTemplate restTemplate;

    private static final String REST_URL_PREFIX = "http://PROVIDER";

    @GetMapping
    public String consumer(@RequestParam String username) {
        String result = restTemplate.getForObject(REST_URL_PREFIX+"/user/provider?username="+username, String.class);
        return  "消费者服务:"+result ;
    }

}

启动消费者服务

package net.riking.springcloud.consumer;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
@EnableEurekaClient
public class AppConsumer {
    public static void main(String[] args) {
        SpringApplication.run(AppConsumer.class, args);
    }

    @Bean
    @LoadBalanced   //如果提供者服务为集群,当在请求时,拥有客户端负载均衡的能力,这里就不做演示
    RestTemplate restTemplate() {
        return new RestTemplate();
    }

}

启动工程后,访问:http://localhost:7001/,可以看到下面的页面中消费者也注册到eureka服务上

访问:http://localhost:9001/user/consumer?username=消费者,可以看到下面的页面中信息输出

Eureka特性

Eureka Server

       失效剔除

       有些时候,我们的服务实例并不一定会正常下线,可能由于内存溢出、网络故障气因使得服务不能正常工作,而服务注册中心并未收到“服务下线”的请求。为了从服务表中将这些无法提供服务的实例剔除,Eureka Server 在启动的时候会创建一个定时任务,默认每隔一一段时间(默认为60秒)将当前清单中超时(默认为90秒)没有续约的服务剔除,如需修改剔除失效服务默认值间隔配置如下

eureka:
server: #剔除失效服务间隔
eviction-interval-timer-in-ms: 5000 # 续期时间,即扫描失效服务的间隔时间(缺省为60*1000ms)

       自我保护

        默认情况下,EurekaClient会定时向EurekaServer端发送心跳,如果EurekaServer在一定时间内没有收到EurekaClient发送的心跳,便会把该实例从注册服务列表中剔除(默认是90秒),但是在短时间内丢失大量的实例心跳,这时候EurekaServer会开启自我保护机制,Eureka不会踢出该服务。

       在开发测试时,需要频繁地重启微服务实例,但是我们很少会把eureka server一起重启(因为在开发过程中不会修改eureka注册中心),当一分钟内收到的心跳数大量减少时,会触发该保护机制。可以在eureka管理界面看到Renews threshold和Renews(last min),当后者(最后一分钟收到的心跳数)小于前者(心跳阈值)的时候,触发保护机制,会出现红色的警告:

        从警告中可以看到,eureka认为虽然收不到实例(PROVIDER)的心跳,但它认为实例还是健康的,eureka会保护这些实例,不会把它们从注册表中删掉。该保护机制的目的是避免网络连接故障,在发生网络故障时,微服务和注册中心之间无法正常通信,但服务本身是健康的,不应该注销该服务,如果eureka因网络故障而把微服务误删了,那即使网络恢复了,该微服务也不会重新注册到eureka server了,因为只有在微服务启动的时候才会发起注册请求,后面只会发送心跳和服务列表请求,这样的话,该实例虽然是运行着,但永远不会被其它服务所感知。所以,eureka server在短时间内丢失过多的客户端心跳时,会进入自我保护模式,该模式下,eureka会保护注册表中的信息,不在注销任何微服务,当网络故障恢复后,eureka会自动退出保护模式。自我保护模式可以让集群更加健壮。
       但是我们在开发测试阶段,需要频繁地重启发布,如果触发了保护机制,则旧的服务实例没有被删除,这时请求有可能跑到旧的实例中,而该实例已经关闭了,这就导致请求错误,影响开发测试。所以,在开发测试阶段,我们可以把自我保护模式关闭,只需在eureka server配置文件中加上如下配置即可:

eureka:
  server:
    enable-self-preservation: false           # 关闭自我保护模式(缺省为打开)
    eviction-interval-timer-in-ms: 5000       # 续期时间,即扫描失效服务的间隔时间(缺省为60*1000ms)

但在生产环境,不会频繁重启,所以,一定要把自我保护机制打开,否则网络一旦终端,就无法恢复。
当然关于自我保护还有很多个性化配置,这里不详细说明。

       server完整参数列表

/*  版本路径spring-cloud-netflix-eureka-server-2.0.0.M7.jarMETA-INFspring-configuration-metadata.json               */
{
  "hints": [],
  "groups": [
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaDashboardProperties",
      "name": "eureka.dashboard",
      "type": "org.springframework.cloud.netflix.eureka.server.EurekaDashboardProperties"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.InstanceRegistryProperties",
      "name": "eureka.instance.registry",
      "type": "org.springframework.cloud.netflix.eureka.server.InstanceRegistryProperties"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "name": "eureka.server",
      "type": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean"
    }
  ],
  "properties": [
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaDashboardProperties",
      "defaultValue": true,
      "name": "eureka.dashboard.enabled",
      "description": "Flag to enable the Eureka dashboard. Default true.",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaDashboardProperties",
      "defaultValue": "/",
      "name": "eureka.dashboard.path",
      "description": "The path to the Eureka dashboard (relative to the servlet path). Defaults to "/".",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.InstanceRegistryProperties",
      "defaultValue": 1,
      "name": "eureka.instance.registry.default-open-for-traffic-count",
      "description": "Value used in determining when leases are cancelled, default to 1 for standalone.
 Should be set to 0 for peer replicated eurekas",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.InstanceRegistryProperties",
      "defaultValue": 1,
      "name": "eureka.instance.registry.expected-number-of-renews-per-min",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 0,
      "name": "eureka.server.a-s-g-cache-expiry-timeout-ms",
      "type": "java.lang.Long"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 300,
      "name": "eureka.server.a-s-g-query-timeout-ms",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 0,
      "name": "eureka.server.a-s-g-update-interval-ms",
      "type": "java.lang.Long"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "name": "eureka.server.a-w-s-access-id",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "name": "eureka.server.a-w-s-secret-key",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": false,
      "name": "eureka.server.batch-replication",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "name": "eureka.server.binding-strategy",
      "type": "com.netflix.eureka.aws.AwsBindingStrategy"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 0,
      "name": "eureka.server.delta-retention-timer-interval-in-ms",
      "type": "java.lang.Long"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": false,
      "name": "eureka.server.disable-delta",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": false,
      "name": "eureka.server.disable-delta-for-remote-regions",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": false,
      "name": "eureka.server.disable-transparent-fallback-to-other-region",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 3,
      "name": "eureka.server.e-i-p-bind-rebind-retries",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 0,
      "name": "eureka.server.e-i-p-binding-retry-interval-ms",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 0,
      "name": "eureka.server.e-i-p-binding-retry-interval-ms-when-unbound",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": false,
      "name": "eureka.server.enable-replicated-request-compression",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": true,
      "name": "eureka.server.enable-self-preservation",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 0,
      "name": "eureka.server.eviction-interval-timer-in-ms",
      "type": "java.lang.Long"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": true,
      "name": "eureka.server.g-zip-content-from-remote-region",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "name": "eureka.server.json-codec-name",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": "ListAutoScalingGroups",
      "name": "eureka.server.list-auto-scaling-groups-role-name",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": true,
      "name": "eureka.server.log-identity-headers",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 10000,
      "name": "eureka.server.max-elements-in-peer-replication-pool",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 10000,
      "name": "eureka.server.max-elements-in-status-replication-pool",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 15,
      "name": "eureka.server.max-idle-thread-age-in-minutes-for-peer-replication",
      "type": "java.lang.Long"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 10,
      "name": "eureka.server.max-idle-thread-in-minutes-age-for-status-replication",
      "type": "java.lang.Long"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 20,
      "name": "eureka.server.max-threads-for-peer-replication",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 1,
      "name": "eureka.server.max-threads-for-status-replication",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 30000,
      "name": "eureka.server.max-time-for-replication",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": -1,
      "name": "eureka.server.min-available-instances-for-peer-replication",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 5,
      "name": "eureka.server.min-threads-for-peer-replication",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 1,
      "name": "eureka.server.min-threads-for-status-replication",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 5,
      "name": "eureka.server.number-of-replication-retries",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 0,
      "name": "eureka.server.peer-eureka-nodes-update-interval-ms",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 0,
      "name": "eureka.server.peer-eureka-status-refresh-time-interval-ms",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 200,
      "name": "eureka.server.peer-node-connect-timeout-ms",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 30,
      "name": "eureka.server.peer-node-connection-idle-timeout-seconds",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 200,
      "name": "eureka.server.peer-node-read-timeout-ms",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 1000,
      "name": "eureka.server.peer-node-total-connections",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 500,
      "name": "eureka.server.peer-node-total-connections-per-host",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": true,
      "name": "eureka.server.prime-aws-replica-connections",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "name": "eureka.server.property-resolver",
      "type": "org.springframework.core.env.PropertyResolver"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 10,
      "name": "eureka.server.rate-limiter-burst-size",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": false,
      "name": "eureka.server.rate-limiter-enabled",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 100,
      "name": "eureka.server.rate-limiter-full-fetch-average-rate",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "name": "eureka.server.rate-limiter-privileged-clients",
      "type": "java.util.Set<java.lang.String>"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 500,
      "name": "eureka.server.rate-limiter-registry-fetch-average-rate",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": false,
      "name": "eureka.server.rate-limiter-throttle-standard-clients",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 0,
      "name": "eureka.server.registry-sync-retries",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 0,
      "name": "eureka.server.registry-sync-retry-wait-ms",
      "type": "java.lang.Long"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "name": "eureka.server.remote-region-app-whitelist",
      "type": "java.util.Map<java.lang.String,java.util.Set<java.lang.String>>"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 1000,
      "name": "eureka.server.remote-region-connect-timeout-ms",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 30,
      "name": "eureka.server.remote-region-connection-idle-timeout-seconds",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 20,
      "name": "eureka.server.remote-region-fetch-thread-pool-size",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 1000,
      "name": "eureka.server.remote-region-read-timeout-ms",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 30,
      "name": "eureka.server.remote-region-registry-fetch-interval",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 1000,
      "name": "eureka.server.remote-region-total-connections",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 500,
      "name": "eureka.server.remote-region-total-connections-per-host",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": "",
      "name": "eureka.server.remote-region-trust-store",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": "changeit",
      "name": "eureka.server.remote-region-trust-store-password",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "name": "eureka.server.remote-region-urls",
      "type": "java.lang.String[]"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "name": "eureka.server.remote-region-urls-with-name",
      "type": "java.util.Map<java.lang.String,java.lang.String>"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 0.85,
      "name": "eureka.server.renewal-percent-threshold",
      "type": "java.lang.Double"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 0,
      "name": "eureka.server.renewal-threshold-update-interval-ms",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 180,
      "name": "eureka.server.response-cache-auto-expiration-in-seconds",
      "type": "java.lang.Long"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 0,
      "name": "eureka.server.response-cache-update-interval-ms",
      "type": "java.lang.Long"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 0,
      "name": "eureka.server.retention-time-in-m-s-in-delta-queue",
      "type": "java.lang.Long"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 3,
      "name": "eureka.server.route53-bind-rebind-retries",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 0,
      "name": "eureka.server.route53-binding-retry-interval-ms",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 30,
      "name": "eureka.server.route53-domain-t-t-l",
      "type": "java.lang.Long"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": true,
      "name": "eureka.server.sync-when-timestamp-differs",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": true,
      "name": "eureka.server.use-read-only-response-cache",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "defaultValue": 0,
      "name": "eureka.server.wait-time-in-ms-when-sync-empty",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
      "name": "eureka.server.xml-codec-name",
      "type": "java.lang.String"
    }
  ]
}
View Code

Eureka Client

        心跳时间

        EurekaClient向EurekaServer发送的心跳,从而EurekaServer便会把该实例从注册服务列表中剔除。

eureka:
  instance:
    lease-renewal-interval-in-seconds: 5      # 心跳时间,即服务续约间隔时间(缺省为30s)
    lease-expiration-duration-in-seconds: 10  # 发呆时间,即服务续约到期时间(缺省为90s)
  client:
    healthcheck:
      enabled: true                           # 开启健康检查(依赖spring-boot-starter-actuator)

       对于lease-renewal-interval-in-seconds(心跳时间)与lease-expiration-duration-in-seconds(发呆时间),我的理解是EurekaClient端每隔30S向EurekaServer端发送心跳,当EurekaClient连续发送3次(90S)心跳eureka server都未能收到,eureka server就会剔除该instance,即eureka server至上一次收到client的心跳之后,等待下一次心跳的超时时间,在这个时间内若没收到下一次心跳,则将移除该instance。

      信息获取

       自动获取:客户端启动的时候,使用服务别名,会发送一个rest请求到服务注册中心获取对应的服务信息,然后会缓存到本地jvm客户端中,同时客户端每隔30秒从服务器上更新一次。可以通过 registry-fetch-interval-seconds=30参数进行修改。

eureka:
  client:
#表示eureka client间隔多久去拉取服务注册信息,默认为30秒,对于api-gateway,如果要迅速获取服务注册状态,可以缩小该值,比如5秒 registry-fetch-interval-seconds: 5

      手动获取:

package net.riking.springcloud.provider.controller;

import net.riking.springcloud.provider.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/provider")
public class UserProviderController {

    @Autowired
    private DiscoveryClient client;

    @GetMapping
    public User provider(@RequestParam String username) {
        User user = new User();
        user.setUsername(username);
        user.setPassword("provider-eureka7001");
        user.setDescription("注册服务提供者");
        return  user ;
    }


    @GetMapping(value = "/discovery")
    public Object discovery()
    {
        List<String> list = client.getServices();
        list.stream().forEach(a->
                {
                    List<ServiceInstance> srvList = client.getInstances(a);
                    srvList.stream().forEach(element->System.out.println("ServiceId:"+element.getServiceId() + "	 Host:" + element.getHost() + "	 Port:"
                            + element.getPort() + "	 Uri:"+ element.getUri()));
                }
            );
        return this.client;
    }
}

访问:http://localhost:9001//user/provider,控制台输出如下

ServiceId:PROVIDER     Host:rikingsht093.RIKING.NET     Port:8001     Uri:http://rikingsht093.RIKING.NET:8001

       服务下线   

       在系统运行过程中必然会面临关闭或重启服务的某个实例的情况,在服务关闭期有我们自然不希望客户端会继续调用关闭了的实例。所以在客户端程序中,当服务实例过正常的关闭操作时,它会触发一个服务下线的REST请求给Eureka Server, 告诉服务日中心:“我要下线了”。服务端在接收到请求之后,将该服务状态置为下线(DOWN),井该下线事件传播出去。

       client完整参数列表

/* 版本路径spring-cloud-netflix-eureka-client-2.0.0.M7.jarMETA-INFspring-configuration-metadata.json  */
{
  "hints": [],
  "groups": [
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "name": "eureka.client",
      "type": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "name": "eureka.client.transport",
      "sourceMethod": "getTransport()",
      "type": "com.netflix.discovery.shared.transport.EurekaTransportConfig"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "name": "eureka.instance",
      "type": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean"
    }
  ],
  "properties": [
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": false,
      "name": "eureka.client.allow-redirects",
      "description": "Indicates whether server can redirect a client request to a backup server/cluster.
 If set to false, the server will handle the request directly, If set to true, it
 may send HTTP redirect to the client, with a new server location.",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "name": "eureka.client.availability-zones",
      "description": "Gets the list of availability zones (used in AWS data centers) for the region in
 which this instance resides.

 The changes are effective at runtime at the next registry fetch cycle as specified
 by registryFetchIntervalSeconds.",
      "type": "java.util.Map<java.lang.String,java.lang.String>"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "name": "eureka.client.backup-registry-impl",
      "description": "Gets the name of the implementation which implements BackupRegistry to fetch the
 registry information as a fall back option for only the first time when the eureka
 client starts.

 This may be needed for applications which needs additional resiliency for registry
 information without which it cannot operate.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": 10,
      "name": "eureka.client.cache-refresh-executor-exponential-back-off-bound",
      "description": "Cache refresh executor exponential back off related property. It is a maximum
 multiplier value for retry delay, in case where a sequence of timeouts occurred.",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": 2,
      "name": "eureka.client.cache-refresh-executor-thread-pool-size",
      "description": "The thread pool size for the cacheRefreshExecutor to initialise with",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "name": "eureka.client.client-data-accept",
      "description": "EurekaAccept name for client data accept",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "name": "eureka.client.decoder-name",
      "description": "This is a transient config and once the latest codecs are stable, can be removed
 (as there will only be one)",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": false,
      "name": "eureka.client.disable-delta",
      "description": "Indicates whether the eureka client should disable fetching of delta and should
 rather resort to getting the full registry information.

 Note that the delta fetches can reduce the traffic tremendously, because the rate
 of change with the eureka server is normally much lower than the rate of fetches.

 The changes are effective at runtime at the next registry fetch cycle as specified
 by registryFetchIntervalSeconds",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": "_-",
      "name": "eureka.client.dollar-replacement",
      "description": "Get a replacement string for Dollar sign <code>$</code> during
 serializing/deserializing information in eureka server.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": true,
      "name": "eureka.client.enabled",
      "description": "Flag to indicate that the Eureka client is enabled.",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "name": "eureka.client.encoder-name",
      "description": "This is a transient config and once the latest codecs are stable, can be removed
 (as there will only be one)",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": "__",
      "name": "eureka.client.escape-char-replacement",
      "description": "Get a replacement string for underscore sign <code>_</code> during
 serializing/deserializing information in eureka server.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": 30,
      "name": "eureka.client.eureka-connection-idle-timeout-seconds",
      "description": "Indicates how much time (in seconds) that the HTTP connections to eureka server can
 stay idle before it can be closed.

 In the AWS environment, it is recommended that the values is 30 seconds or less,
 since the firewall cleans up the connection information after a few mins leaving
 the connection hanging in limbo",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": 5,
      "name": "eureka.client.eureka-server-connect-timeout-seconds",
      "description": "Indicates how long to wait (in seconds) before a connection to eureka server needs
 to timeout. Note that the connections in the client are pooled by
 org.apache.http.client.HttpClient and this setting affects the actual connection
 creation and also the wait time to get the connection from the pool.",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "name": "eureka.client.eureka-server-d-n-s-name",
      "description": "Gets the DNS name to be queried to get the list of eureka servers.This information
 is not required if the contract returns the service urls by implementing
 serviceUrls.

 The DNS mechanism is used when useDnsForFetchingServiceUrls is set to true and the
 eureka client expects the DNS to configured a certain way so that it can fetch
 changing eureka servers dynamically.

 The changes are effective at runtime.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "name": "eureka.client.eureka-server-port",
      "description": "Gets the port to be used to construct the service url to contact eureka server when
 the list of eureka servers come from the DNS.This information is not required if
 the contract returns the service urls eurekaServerServiceUrls(String).

 The DNS mechanism is used when useDnsForFetchingServiceUrls is set to true and the
 eureka client expects the DNS to configured a certain way so that it can fetch
 changing eureka servers dynamically.

 The changes are effective at runtime.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": 8,
      "name": "eureka.client.eureka-server-read-timeout-seconds",
      "description": "Indicates how long to wait (in seconds) before a read from eureka server needs to
 timeout.",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": 200,
      "name": "eureka.client.eureka-server-total-connections",
      "description": "Gets the total number of connections that is allowed from eureka client to all
 eureka servers.",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": 50,
      "name": "eureka.client.eureka-server-total-connections-per-host",
      "description": "Gets the total number of connections that is allowed from eureka client to a eureka
 server host.",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "name": "eureka.client.eureka-server-u-r-l-context",
      "description": "Gets the URL context to be used to construct the service url to contact eureka
 server when the list of eureka servers come from the DNS. This information is not
 required if the contract returns the service urls from eurekaServerServiceUrls.

 The DNS mechanism is used when useDnsForFetchingServiceUrls is set to true and the
 eureka client expects the DNS to configured a certain way so that it can fetch
 changing eureka servers dynamically. The changes are effective at runtime.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": 0,
      "name": "eureka.client.eureka-service-url-poll-interval-seconds",
      "description": "Indicates how often(in seconds) to poll for changes to eureka server information.
 Eureka servers could be added or removed and this setting controls how soon the
 eureka clients should know about it.",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": true,
      "name": "eureka.client.fetch-registry",
      "description": "Indicates whether this client should fetch eureka registry information from eureka
 server.",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "name": "eureka.client.fetch-remote-regions-registry",
      "description": "Comma separated list of regions for which the eureka registry information will be
 fetched. It is mandatory to define the availability zones for each of these regions
 as returned by availabilityZones. Failing to do so, will result in failure of
 discovery client startup.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": true,
      "name": "eureka.client.filter-only-up-instances",
      "description": "Indicates whether to get the applications after filtering the applications for
 instances with only InstanceStatus UP states.",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": true,
      "name": "eureka.client.g-zip-content",
      "description": "Indicates whether the content fetched from eureka server has to be compressed
 whenever it is supported by the server. The registry information from the eureka
 server is compressed for optimum network traffic.",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": 10,
      "name": "eureka.client.heartbeat-executor-exponential-back-off-bound",
      "description": "Heartbeat executor exponential back off related property. It is a maximum
 multiplier value for retry delay, in case where a sequence of timeouts occurred.",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": 2,
      "name": "eureka.client.heartbeat-executor-thread-pool-size",
      "description": "The thread pool size for the heartbeatExecutor to initialise with",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": 40,
      "name": "eureka.client.initial-instance-info-replication-interval-seconds",
      "description": "Indicates how long initially (in seconds) to replicate instance info to the eureka
 server",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": 30,
      "name": "eureka.client.instance-info-replication-interval-seconds",
      "description": "Indicates how often(in seconds) to replicate instance changes to be replicated to
 the eureka server.",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": false,
      "name": "eureka.client.log-delta-diff",
      "description": "Indicates whether to log differences between the eureka server and the eureka
 client in terms of registry information.

 Eureka client tries to retrieve only delta changes from eureka server to minimize
 network traffic. After receiving the deltas, eureka client reconciles the
 information from the server to verify it has not missed out some information.
 Reconciliation failures could happen when the client has had network issues
 communicating to server.If the reconciliation fails, eureka client gets the full
 registry information.

 While getting the full registry information, the eureka client can log the
 differences between the client and the server and this setting controls that.

 The changes are effective at runtime at the next registry fetch cycle as specified
 by registryFetchIntervalSecondsr",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": true,
      "name": "eureka.client.on-demand-update-status-change",
      "description": "If set to true, local status updates via ApplicationInfoManager will trigger
 on-demand (but rate limited) register/updates to remote eureka servers",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": true,
      "name": "eureka.client.prefer-same-zone-eureka",
      "description": "Indicates whether or not this instance should try to use the eureka server in the
 same zone for latency and/or other reason.

 Ideally eureka clients are configured to talk to servers in the same zone

 The changes are effective at runtime at the next registry fetch cycle as specified
 by registryFetchIntervalSeconds",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "name": "eureka.client.property-resolver",
      "type": "org.springframework.core.env.PropertyResolver"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "name": "eureka.client.proxy-host",
      "description": "Gets the proxy host to eureka server if any.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "name": "eureka.client.proxy-password",
      "description": "Gets the proxy password if any.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "name": "eureka.client.proxy-port",
      "description": "Gets the proxy port to eureka server if any.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "name": "eureka.client.proxy-user-name",
      "description": "Gets the proxy user name if any.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": "us-east-1",
      "name": "eureka.client.region",
      "description": "Gets the region (used in AWS datacenters) where this instance resides.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": true,
      "name": "eureka.client.register-with-eureka",
      "description": "Indicates whether or not this instance should register its information with eureka
 server for discovery by others.

 In some cases, you do not want your instances to be discovered whereas you just
 want do discover other instances.",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": 30,
      "name": "eureka.client.registry-fetch-interval-seconds",
      "description": "Indicates how often(in seconds) to fetch the registry information from the eureka
 server.",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "name": "eureka.client.registry-refresh-single-vip-address",
      "description": "Indicates whether the client is only interested in the registry information for a
 single VIP.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "name": "eureka.client.service-url",
      "description": "Map of availability zone to list of fully qualified URLs to communicate with eureka
 server. Each value can be a single URL or a comma separated list of alternative
 locations.

 Typically the eureka server URLs carry protocol,host,port,context and version
 information if any. Example:
 http://ec2-256-156-243-129.compute-1.amazonaws.com:7001/eureka/

 The changes are effective at runtime at the next service url refresh cycle as
 specified by eurekaServiceUrlPollIntervalSeconds.",
      "type": "java.util.Map<java.lang.String,java.lang.String>"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": false,
      "name": "eureka.client.should-enforce-registration-at-init",
      "description": "Indicates whether the client should enforce registration during initialization. Defaults to false.",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": true,
      "name": "eureka.client.should-unregister-on-shutdown",
      "description": "Indicates whether the client should explicitly unregister itself from the remote server
 on client shutdown.",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
      "defaultValue": false,
      "name": "eureka.client.use-dns-for-fetching-service-urls",
      "description": "Indicates whether the eureka client should use the DNS mechanism to fetch a list of
 eureka servers to talk to. When the DNS name is updated to have additional servers,
 that information is used immediately after the eureka client polls for that
 information as specified in eurekaServiceUrlPollIntervalSeconds.

 Alternatively, the service urls can be returned serviceUrls, but the users should
 implement their own mechanism to return the updated list in case of changes.

 The changes are effective at runtime.",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "name": "eureka.instance.a-s-g-name",
      "description": "Gets the AWS autoscaling group name associated with this instance. This information
 is specifically used in an AWS environment to automatically put an instance out of
 service after the instance is launched and it has been disabled for traffic..",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "name": "eureka.instance.app-group-name",
      "description": "Get the name of the application group to be registered with eureka.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "defaultValue": "unknown",
      "name": "eureka.instance.appname",
      "description": "Get the name of the application to be registered with eureka.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "name": "eureka.instance.data-center-info",
      "description": "Returns the data center this instance is deployed. This information is used to get
 some AWS specific instance information if the instance is deployed in AWS.",
      "type": "com.netflix.appinfo.DataCenterInfo"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "defaultValue": [],
      "name": "eureka.instance.default-address-resolution-order",
      "type": "java.lang.String[]"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "name": "eureka.instance.environment",
      "type": "org.springframework.core.env.Environment"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "name": "eureka.instance.health-check-url",
      "description": "Gets the absolute health check page URL for this instance. The users can provide
 the healthCheckUrlPath if the health check page resides in the same instance
 talking to eureka, else in the cases where the instance is a proxy for some other
 server, users can provide the full URL. If the full URL is provided it takes
 precedence.

 <p>
 It is normally used for making educated decisions based on the health of the
 instance - for example, it can be used to determine whether to proceed deployments
 to an entire farm or stop the deployments without causing further damage. The full
 URL should follow the format http://${eureka.hostname}:7001/ where the value
 ${eureka.hostname} is replaced at runtime.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "defaultValue": "/health",
      "name": "eureka.instance.health-check-url-path",
      "description": "Gets the relative health check URL path for this instance. The health check page
 URL is then constructed out of the hostname and the type of communication - secure
 or unsecure as specified in securePort and nonSecurePort.

 It is normally used for making educated decisions based on the health of the
 instance - for example, it can be used to determine whether to proceed deployments
 to an entire farm or stop the deployments without causing further damage.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "name": "eureka.instance.home-page-url",
      "description": "Gets the absolute home page URL for this instance. The users can provide the
 homePageUrlPath if the home page resides in the same instance talking to eureka,
 else in the cases where the instance is a proxy for some other server, users can
 provide the full URL. If the full URL is provided it takes precedence.

 It is normally used for informational purposes for other services to use it as a
 landing page. The full URL should follow the format http://${eureka.hostname}:7001/
 where the value ${eureka.hostname} is replaced at runtime.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "defaultValue": "/",
      "name": "eureka.instance.home-page-url-path",
      "description": "Gets the relative home page URL Path for this instance. The home page URL is then
 constructed out of the hostName and the type of communication - secure or unsecure.

 It is normally used for informational purposes for other services to use it as a
 landing page.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "name": "eureka.instance.hostname",
      "description": "The hostname if it can be determined at configuration time (otherwise it will be
 guessed from OS primitives).",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "name": "eureka.instance.initial-status",
      "description": "Initial status to register with rmeote Eureka server.",
      "type": "com.netflix.appinfo.InstanceInfo$InstanceStatus"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "defaultValue": false,
      "name": "eureka.instance.instance-enabled-onit",
      "description": "Indicates whether the instance should be enabled for taking traffic as soon as it
 is registered with eureka. Sometimes the application might need to do some
 pre-processing before it is ready to take traffic.",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "name": "eureka.instance.instance-id",
      "description": "Get the unique Id (within the scope of the appName) of this instance to be
 registered with eureka.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "name": "eureka.instance.ip-address",
      "description": "Get the IPAdress of the instance. This information is for academic purposes only as
 the communication from other instances primarily happen using the information
 supplied in {@link #getHostName(boolean)}.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "defaultValue": 90,
      "name": "eureka.instance.lease-expiration-duration-in-seconds",
      "description": "Indicates the time in seconds that the eureka server waits since it received the
 last heartbeat before it can remove this instance from its view and there by
 disallowing traffic to this instance.

 Setting this value too long could mean that the traffic could be routed to the
 instance even though the instance is not alive. Setting this value too small could
 mean, the instance may be taken out of traffic because of temporary network
 glitches.This value to be set to atleast higher than the value specified in
 leaseRenewalIntervalInSeconds.",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "defaultValue": 30,
      "name": "eureka.instance.lease-renewal-interval-in-seconds",
      "description": "Indicates how often (in seconds) the eureka client needs to send heartbeats to
 eureka server to indicate that it is still alive. If the heartbeats are not
 received for the period specified in leaseExpirationDurationInSeconds, eureka
 server will remove the instance from its view, there by disallowing traffic to this
 instance.

 Note that the instance could still not take traffic if it implements
 HealthCheckCallback and then decides to make itself unavailable.",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "name": "eureka.instance.metadata-map",
      "description": "Gets the metadata name/value pairs associated with this instance. This information
 is sent to eureka server and can be used by other instances.",
      "type": "java.util.Map<java.lang.String,java.lang.String>"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "defaultValue": "eureka",
      "name": "eureka.instance.namespace",
      "description": "Get the namespace used to find properties. Ignored in Spring Cloud.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "defaultValue": 80,
      "name": "eureka.instance.non-secure-port",
      "description": "Get the non-secure port on which the instance should receive traffic.",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "defaultValue": true,
      "name": "eureka.instance.non-secure-port-enabled",
      "description": "Indicates whether the non-secure port should be enabled for traffic or not.",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "defaultValue": false,
      "name": "eureka.instance.prefer-ip-address",
      "description": "Flag to say that, when guessing a hostname, the IP address of the server should be
 used in prference to the hostname reported by the OS.",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "name": "eureka.instance.secure-health-check-url",
      "description": "Gets the absolute secure health check page URL for this instance. The users can
 provide the secureHealthCheckUrl if the health check page resides in the same
 instance talking to eureka, else in the cases where the instance is a proxy for
 some other server, users can provide the full URL. If the full URL is provided it
 takes precedence.

 <p>
 It is normally used for making educated decisions based on the health of the
 instance - for example, it can be used to determine whether to proceed deployments
 to an entire farm or stop the deployments without causing further damage. The full
 URL should follow the format http://${eureka.hostname}:7001/ where the value
 ${eureka.hostname} is replaced at runtime.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "defaultValue": 443,
      "name": "eureka.instance.secure-port",
      "description": "Get the Secure port on which the instance should receive traffic.",
      "type": "java.lang.Integer"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "defaultValue": false,
      "name": "eureka.instance.secure-port-enabled",
      "description": "Indicates whether the secure port should be enabled for traffic or not.",
      "type": "java.lang.Boolean"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "defaultValue": "unknown",
      "name": "eureka.instance.secure-virtual-host-name",
      "description": "Gets the secure virtual host name defined for this instance.

 This is typically the way other instance would find this instance by using the
 secure virtual host name.Think of this as similar to the fully qualified domain
 name, that the users of your services will need to find this instance.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "name": "eureka.instance.status-page-url",
      "description": "Gets the absolute status page URL path for this instance. The users can provide the
 statusPageUrlPath if the status page resides in the same instance talking to
 eureka, else in the cases where the instance is a proxy for some other server,
 users can provide the full URL. If the full URL is provided it takes precedence.

 It is normally used for informational purposes for other services to find about the
 status of this instance. Users can provide a simple HTML indicating what is the
 current status of the instance.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "defaultValue": "/info",
      "name": "eureka.instance.status-page-url-path",
      "description": "Gets the relative status page URL path for this instance. The status page URL is
 then constructed out of the hostName and the type of communication - secure or
 unsecure as specified in securePort and nonSecurePort.

 It is normally used for informational purposes for other services to find about the
 status of this instance. Users can provide a simple HTML indicating what is the
 current status of the instance.",
      "type": "java.lang.String"
    },
    {
      "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
      "defaultValue": "unknown",
      "name": "eureka.instance.virtual-host-name",
      "description": "Gets the virtual host name defined for this instance.

 This is typically the way other instance would find this instance by using the
 virtual host name.Think of this as similar to the fully qualified domain name, that
 the users of your services will need to find this instance.",
      "type": "java.lang.String"
    }
  ]
}
View Code

引申:

  1. @EnableDiscoveryClient和@EnableEurekaClient异同点

       从Spring Cloud Edgware开始,@EnableDiscoveryClient 或@EnableEurekaClient 可省略。只需加上相关依赖,并进行相应配置,即可将微服务注册到服务发现组件上。

  • 相同点:都是能够让注册中心能够发现,扫描到该服务。
  • 不同点:@EnableEurekaClient只适用于Eureka作为注册中心,@EnableDiscoveryClient 可以是其他注册中心(Consul、Zookeeper)。
原文地址:https://www.cnblogs.com/kongliuyi/p/11315727.html