spring cloud 文档阅读

This commit is contained in:
2023-03-27 18:28:44 +08:00
parent af390d79b2
commit 88d8d4abd3

View File

@@ -82,3 +82,38 @@ public String serviceUrl() {
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
```
### Eureka Server的启动
如下显示了要启动一个Eureka Server的最简代码
```java
@SpringBootApplication
@EnableEurekaServer
public class Application {
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).web(true).run(args);
}
}
```
`/eureka/*`路径下该eureka server拥有UI和http api endpoint。
### 高可用
Eureka Server并没有后端存储但是注册到Eureka Server中的所有service实例都必须向eureka server发送心跳包来保证其注册状态是最新的上述所有操作都是在eureka server的内存中完成的。
client端也会在内存中对eureka server中的注册状态进行缓存故而无需每次请求其他service时都要从eureka server中获取注册状态。
> 默认情况下每个eureka server都同时是一个client并且需要至少一个URL来定位其他的service实例。
### 单机模式
单机模式下,可以通过如下配置来关闭客户端的行为:
```yml
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
```