转载

Spring Cloud Gateway 注册到服务中心 Consul,代理服务中心的所有服务

Spring Cloud Gateway 提供了一种默认转发的能力,只要将 Spring Cloud Gateway 注册到服务中心,Spring Cloud Gateway 默认就会代理服务中心的所有服务。

步骤一:创建项目

  1. 选择 Gateway 和 Consul

步骤二:配置 src/main/resources/application.properties 文件

spring.cloud.gateway.discovery.locator.enabled
spring.cloud.consul.host=127.0.0.1
spring.cloud.consul.port=8500
# 设置不需要注册到 consul 中
spring.cloud.consul.discovery.register=false
复制代码

步骤三:创建 Consul 容器

1.镜像官方网址: hub.docker.com/_/consul

2.pull 镜像:

docker pull consul:1.6.0
复制代码

3.创建容器(默认http管理端口:8500)

docker run -p 8500:8500 consul:1.6.0
复制代码

4.访问管理网址

http://localhost:8500/
复制代码
原文  https://juejin.im/post/5d82f0caf265da03ec2e9b97
正文到此结束
Loading...