SpringBoot系列

7) Eureka服务注册与发现

2021-03-06  本文已影响0人  涣涣虚心0215

代码示例

Eureka Server

@EnableEurekaServer

eureka:
  server:
    eviction-interval-timer-in-ms: 1000 #设置清理的间隔时间,而后这个时间使用的是毫秒单位(默认是60秒,如果不配置,服务停止之后,仍然显示在Eureka上)
    enable-self-preservation: true #设置为false表示关闭保护模式(保护模式就是防止服务以外down了之后,不会立即清理掉,还能保留在注册中心一段时间)
  instance:
    hostname: localhost
  client:
    #声明自己是个服务端
    registerWithEureka: false #表示不向注册中心注册自己
   fetchRegistry: false #是否获取注册信息,表示自己端就是注册中心,只是维护实例
   serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
Eureka Client

@EnableDiscoveryClient

eureka:
  client: #作为服务消费者的配置
    healthcheck:
      enabled: true
    fetch-registry: true
    register-with-eureka: true
    instance-info-replication-interval-seconds: 10 #每隔10秒扫描一次本地实例,如果有变化向服务重新注册
    registry-fetch-interval-seconds: 10 #缓存清单更新时间,默认30秒
  instance: #作为服务提供者的配置
    prefer-ip-address: true
    instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}
    lease-renewal-interval-in-seconds: 5 #服务续租间隔,默认是30秒
    lease-expiration-duration-in-seconds: 10 #服务时效时间,默认是90秒
    status-page-url-path: ${management.endpoints.web.base-path}/info
    health-check-url-path: ${management.endpoints.web.base-path}/health

management: #actuator
  endpoints:
    web:
      base-path: /management
      exposure:
        include: '*'

Eureka关键核心概念和原理:

上一篇 下一篇

猜你喜欢

热点阅读