ITPub博客

首页 > 架构设计 > 软件结构 > (15) java Spring Cloud企业快速开发架构之SpringCloud-使用Eureka集群搭建实现高可用

(15) java Spring Cloud企业快速开发架构之SpringCloud-使用Eureka集群搭建实现高可用

原创 软件结构 作者:JIAN2 时间:2021-09-17 15:50:52 0 删除 编辑

 在实际开发过程中,我们可能会不停地重启服务,由于 Eureka 有自己的保护机制,故节点下线后,服务信息还会一直存在于 Eureka 中。我们可以通过增加一些配置让移除的速度更快一点,当然只在开发环境下使用,生产环境下不推荐使用。 推荐分布式架构源码

需要框架源码的朋友可以看我个人简介联系我

首先在我们的 eureka-server 中增加两个配置,分别是关闭自我保护和清理间隔:

eureka.server.enable-self-preservation=false
# 默认 60000 毫秒
eureka.server.eviction-interval-timer-in-ms=5000


然后在具体的客户端服务中配置下面的内容:

eureka.client.healthcheck.enabled=true
# 默认 30 秒
eureka.instance.lease-renewal-interval-in-seconds=5
# 默认 90 秒
eureka.instance.lease-expiration-duration-in-seconds=5


eureka.client.healthcheck.enabled 用于开启健康检查,需要在 pom.xml 中引入 actuator 的依赖,代码如下所示。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>


其中:

eureka.instance.lease-renewal-interval-in-seconds 表示 Eureka Client 发送心跳给 server 端的频率。
eureka.instance.lease-expiration-duration-in-seconds 表示 Eureka Server 至上一次收到 client 的心跳之后,等待下一次心跳的超时时间,在这个时间内若没收到下一次心跳,则移除该 Instance。

更多的 Instance 配置信息可参考源码中的配置类:org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean。

更多的 Server 配置信息可参考源码中的配置类:org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean。

推荐分布式架构源码


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70006413/viewspace-2792614/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
华为资深架构师,曾参与华为数据中心迁移解决方案!有需要了解分布式微服务电商源码的朋友可以+我 v ❤: haiwabbc2 , 10余年互联网研发行业经验!博客里面是个人的一点技术总结,希望能够帮助到更多的IT朋友成长!

注册时间:2021-09-06

  • 博文量
    1404
  • 访问量
    622704