构建 Eureka 服务端
1. 创建项目
使用 Spring Initializer,选择 Eureka Server、Spring Boot Actuator 和 Config Client,生成项目的 pom.xml 的核心内容如下:
2. 添加配置属性
在 /src/main/resources 文件夹中创建 application.yml 文件:
3. 在引导类上增加 @EnableEurekaServer 注解
4. 在 Config Server 上添加配置
server.port:设置默认端口。
eureka.instance.hostname:设置 Eureka 服务的 Eureka 实例主机名。
eureka.client.registerWithEureka:告诉 Eureka 服务器端别在应用程序启动时注册到 Eureka。
eureka.client.fetchRegistry:当设置为 false 时,告诉 Eureka 服务,当它启动时,不需要在本地缓存其注册表信息。
eureka.client.serviceUrl.defaultZone:连接的 eureka 服务端的地址。
默认情况下,每一个 Eureka 服务同时也是一个 Eureka 客户,因此必须为它配置一个指定对等 Eureka 服务的 URL 地址。
eureka.server.waitTimeInMsWhenSyncEmpty:设置服务器端在开始接受请求之前的等待时间(以毫秒为单位)。
当你本地测试服务时,应该使用这一行属性,因为 Eureka 不会马上通告任何通过它注册的服务。默认情况下,它会等待 5 分钟,让所有的服务都有机会在通告它们之前通过它来注册。进行本地测试时使用这行属性,将有助于加快 Eureka 服务启动和显示通过它注册服务所需的时间。
Last updated