当前位置:网站首页>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");
}
边栏推荐
- 【高并发】SimpleDateFormat类到底为啥不是线程安全的?(附六种解决方案,建议收藏)
- LeetCode 50. Pow(x,n)
- The JSP specification requires that an attribute name is preceded by whitespace
- 【AI4Code】《Unified Pre-training for Program Understanding and Generation》 NAACL 2021
- Brpc source code analysis (VIII) -- detailed explanation of the basic class eventdispatcher
- 【Debias】Model-Agnostic Counterfactual Reasoning for Eliminating Popularity Bias in RS(KDD‘21)
- Zero-Shot Image Retrieval(零样本跨模态检索)
- Zero shot image retrieval (zero sample cross modal retrieval)
- 'C:\xampp\php\ext\php_ zip. Dll'-%1 is not a valid Win32 Application Solution
- 【GCN-RS】MCL: Mixed-Centric Loss for Collaborative Filtering (WWW‘22)
猜你喜欢

【AI4Code】《IntelliCode Compose: Code Generation using Transformer》 ESEC/FSE 2020
![[USB device design] - composite device, dual hid high-speed (64BYTE and 1024byte)](/img/ce/534834c53c72a53fd62ff72a1d3b39.png)
[USB device design] - composite device, dual hid high-speed (64BYTE and 1024byte)

'C:\xampp\php\ext\php_ zip. Dll'-%1 is not a valid Win32 Application Solution

创新突破!亚信科技助力中国移动某省完成核心账务数据库自主可控改造

硬件连接服务器 tcp通讯协议 gateway

【GCN】《Adaptive Propagation Graph Convolutional Network》(TNNLS 2020)

【6篇文章串讲ScalableGNN】围绕WWW 2022 best paper《PaSca》

【Debias】Model-Agnostic Counterfactual Reasoning for Eliminating Popularity Bias in RS(KDD‘21)

Brpc source code analysis (VI) -- detailed explanation of basic socket

JS process control
随机推荐
Start with the development of wechat official account
【Debias】Model-Agnostic Counterfactual Reasoning for Eliminating Popularity Bias in RS(KDD‘21)
Functions in JS
Pycharm connects to the remote server SSH -u reports an error: no such file or directory
Objects in JS
PHP curl post x-www-form-urlencoded
30 sets of Chinese style ppt/ creative ppt templates
【AI4Code最终章】AlphaCode:《Competition-Level Code Generation with AlphaCode》(DeepMind)
【AI4Code】《InferCode: Self-Supervised Learning of Code Representations by Predicting Subtrees》ICSE‘21
Solutions to the failure of winddowns planning task execution bat to execute PHP files
【云驻共创】AI在数学界有哪些作用?未来对数学界会有哪些颠覆性影响?
[GCN multimodal RS] pre training representations of multi modal multi query e-commerce search KDD 2022
JS 面试题:手写节流(throttle)函数
Risks in software testing phase
Application of comparative learning (lcgnn, videomoco, graphcl, XMC GaN)
Web APIs (get element event basic operation element)
Transformer变体(Sparse Transformer,Longformer,Switch Transformer)
Meta learning (meta learning and small sample learning)
'C:\xampp\php\ext\php_zip.dll' - %1 不是有效的 Win32 应用程序 解决
Javescript loop