简体   繁体   English

Spring Cloud Gateway自动路由到Eureka服务

[英]Spring Cloud Gateway auto routing to Eureka services

I work with Spring to create microservices. 我与Spring合作创建微服务。 I am using Eureka for service discovery and Zuul for routing. 我正在使用Eureka进行服务发现,并使用Zuul进行路由。 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. 现在,我想切换到Spring Cloud Gateway(由于具有非阻塞性),但是我没有找到自动路由到每个Eureka服务的方法。

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. 例如,如果一个服务“ eureka-client”注册到了Eureka,Zuul会自行提供一条类似于localhost:8762 / eureka-client的路径。 With Spring Cloud Gateway, I've to create a route all by myself for each service. 使用Spring Cloud Gateway,我必须为每个服务单独创建一条路由。

      routes:
      - id: eureka-client
        uri: lb://eureka-client
        predicates:
        - Path=/eureka-client/**

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中编写自己的路由。

Is there a way to provide auto routing from Spring Cloud Gateway to each service from Eureka? 有没有办法提供从Spring Cloud Gateway到Eureka的每个服务的自动路由?

可以配置自动路由。

spring.cloud.gateway.discovery.locator.enabled=true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM