构建网关服务
1. 创建项目
使用Spring Initializer,选择Reactive Gateway、Eureka Client、Spring Boot Actuator和Config Client,生成项目的pom.xml的核心文件内容如下:
2. 添加配置属性
在/src/main/resources文件夹中创建application.yml文件:
3. 集成Eureka
Spring Cloud Gateway可以与Netflix Eureka Discovery服务集成。要添加新的网关服务,第一步是在Spring配置服务器存储库中为此服务创建一个配置文件。对于这个示例,我们创建了gateway-server.yml文件。
接下来,我们将Eureka配置数据添加到刚刚创建的配置文件中:
通过这样的配置,Spring Cloud Gateway将能够注册到Eureka服务注册中心,并发现其他服务的实例。
4. 配置 Actuator
只有配置了 management.endpoint.gateway.enabled=true 后,才能够访问 gateway 相关的 actuator 端口。
Last updated