问题描述
我与Spring一起创建微服务.我正在使用Eureka进行服务发现,并使用Zuul进行路由.现在,我想切换到Spring Cloud Gateway(由于具有非阻塞性),但是我没有找到自动路由到每个Eureka服务的方法.
I work with Spring to create microservices. I am using Eureka for service discovery and Zuul for routing. Now I wanted to switch to Spring Cloud Gateway (because of non-blocking nature) but I've failed to figure out a way of auto routing to each Eureka service.
例如,如果一个服务"eureka-client"注册到Eureka,Zuul会自行提供一条类似于localhost:8762/eureka-client的路径.使用Spring Cloud Gateway,我必须为每个服务单独创建一条路由.
For example if one service 'eureka-client' registers to Eureka, Zuul does provide a path like localhost:8762/eureka-client to this service by itself. With Spring Cloud Gateway, I've to create a route all by myself for each service.
routes:
- id: eureka-client
uri: lb://eureka-client
predicates:
- Path=/eureka-client/**
有一些可以接受的服务,但最终我可能会获得数百个服务.而且每个人都必须在Spring Cloud Gateway中编写自己的路由.
With a few services that's acceptable but I might get hundreds of services in the end. And each has to write its own route in Spring Cloud Gateway.
是否可以提供从Spring Cloud Gateway到Eureka的每个服务的自动路由?
Is there a way to provide auto routing from Spring Cloud Gateway to each service from Eureka?
推荐答案
自动路由可以是已配置.
spring.cloud.gateway.discovery.locator.enabled=true
这篇关于Spring Cloud Gateway自动路由到Eureka服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!