当前位置:网站首页>Eureka使用记录
Eureka使用记录
2022-07-25 11:21:00 【dengjili】
知识点1,自我保护模式
保护模式主要在一组客户端和 Eureka Server 之间存在网络分区场景时使用。一旦进入保护模式,Eureka Server 将会尝试保护其服务的注册表中的信息,不再删除服务注册表中的数据。当网络故障恢复后,该 Eureka Server 节点会自动退出保护模式。
eureka.server.enableSelfPreservation=false
知识点2,Eureka应用实例ID名称格式
客户端在注册时,服务的 Instance ID 的默认值的格式如下(主机名:服务名称:服务端口):
${
spring.cloud.client.hostname}:${
spring.application.name}:${
spring.application. instance_id:${
server.port}}
若需要自定义格式:服务名称:服务所在 IP:服务端口
eureka.instance.instance-id=${
spring.application.name}:${
spring.cloud.client.ip-address}:${
server.port}

此时上述链接却还是主机名,增加配置,展示为ip
eureka.instance.preferIpAddress=true

自定义跳转链接
eureka.instance.status-page-url-path=/hello

知识点3,Eureka开发时快速移除失效服务
在实际开发过程中,我们可能会不停地重启服务,由于 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。
知识点4,EurekaClient 使用
以下两种方式
- com.netflix.discovery.EurekaClient
@GetMapping("/test")
public Object serviceUrl() {
return eurekaClient.getInstancesByVipAddress("eureka-provider-app", false);
}
- Spring Cloud 重新封,org.springframework.cloud.client.discovery.DiscoveryClient
@GetMapping("/test2")
public Object serviceUrl2() {
return discoveryClient.getInstances("eureka-provider-app");
}
边栏推荐
- 【图攻防】《Backdoor Attacks to Graph Neural Networks 》(SACMAT‘21)
- GPT plus money (OpenAI CLIP,DALL-E)
- Classification parameter stack of JS common built-in object data types
- return 和 finally的执行顺序 ?各位大佬请看过来,
- 【GCN-RS】MCL: Mixed-Centric Loss for Collaborative Filtering (WWW‘22)
- 【无标题】
- Transformer variants (spark transformer, longformer, switch transformer)
- Multi label image classification
- How to solve the problem of the error reported by the Flink SQL client when connecting to MySQL?
- 【AI4Code最终章】AlphaCode:《Competition-Level Code Generation with AlphaCode》(DeepMind)
猜你喜欢

【AI4Code】CodeX:《Evaluating Large Language Models Trained on Code》(OpenAI)

【AI4Code】《InferCode: Self-Supervised Learning of Code Representations by Predicting Subtrees》ICSE‘21

dirReader. Readentries compatibility issues. Exception error domexception

Multi label image classification

剑指 Offer 22. 链表中倒数第k个节点

【AI4Code】《CoSQA: 20,000+ Web Queries for Code Search and Question Answering》 ACL 2021

Solutions to the failure of winddowns planning task execution bat to execute PHP files

Application and innovation of low code technology in logistics management

30套中国风PPT/创意PPT模板

对比学习的应用(LCGNN,VideoMoCo,GraphCL,XMC-GAN)
随机推荐
【GCN-RS】Towards Representation Alignment and Uniformity in Collaborative Filtering (KDD‘22)
Functions in JS
Risks in software testing phase
Scott+Scott律所计划对Yuga Labs提起集体诉讼,或将确认NFT是否属于证券产品
NLP知识----pytorch,反向传播,预测型任务的一些小碎块笔记
Learning to pre train graph neural networks
Knowledge maps are used to recommend system problems (mvin, Ctrl, ckan, Kred, gaeat)
基于TCP/IP在同一局域网下的数据传输
【AI4Code最终章】AlphaCode:《Competition-Level Code Generation with AlphaCode》(DeepMind)
Javescript loop
【6篇文章串讲ScalableGNN】围绕WWW 2022 best paper《PaSca》
[high concurrency] a lock faster than read-write lock in high concurrency scenarios. I'm completely convinced after reading it!! (recommended Collection)
Application and innovation of low code technology in logistics management
[MySQL 17] installation exception: could not open file '/var/log/mysql/mysqld log‘ for error logging: Permission denied
Go 垃圾回收器指南
【AI4Code】《InferCode: Self-Supervised Learning of Code Representations by Predicting Subtrees》ICSE‘21
The JSP specification requires that an attribute name is preceded by whitespace
Introduction to pl/sql, very detailed notes
Transformer变体(Routing Transformer,Linformer,Big Bird)
微信公众号开发 入手