Zuul 无法路由到在尤里卡服务器中注册的应用程序

Zuul unable to route to application registered in eureka server

我正在开发一个微服务,我正在尝试使用 Zuul 代理来通过服务进行路由。但是由于某种原因,Zuul 无法路由到在 eureka 中注册的应用程序。 我尝试增加 hystrix 和 Zuul 超时但没有任何效果

抛出异常

com.netflix.zuul.exception.ZuulException: Forwarding error at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.handleException(RibbonRoutingFilter.java:198) ~[spring-cloud-netflix-zuul-2.2.10.RELEASE.jar:2.2.10.RELEASE]

祖尔application.yml

server:
  port: 8082

spring:
  application:
    name: gateway
eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    serviceUrl:
      defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
  instance:
    hostname: localhost

ribbon:
  eureka:
    enabled: true

zuul:
  ignoredServices: "*"
  host:
    connect-timeout-millis: 5000000
    socket-timeout-millis: 5000000
  prefix: /api
  routes:
    game:
      path: /game/**
      serviceId: game
    trend:
      path: /trend/**
      serviceId: trend

这里我有两个名为“game”和“trend”的微服务都在 eureka 服务中注册,但无法通过 Zuul 代理导航到应用程序。

经过一些研究,我发现 Ribbon、Zuul 处于维护模式,我们不会获得任何新版本,spring 还提出了 Ribbon、Zuul 等的替代方案。请参考此 link for spring alternative 用于负载平衡、代理服务器等

对于这个问题,我使用了 spring 云网关,而不是 spring

提供的替代方案 Zuul

必需的依赖项

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
            <version>3.1.0</version>
        </dependency>

现在代理服务器的应用程序yml如下所示

server:
  port: 8082

spring:
  application:
    name: gateway
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true
          lower-case-service-id: true
      routes:
        - id: game
          uri: lb://game
          predicates:
            - Path=/game/**
        - id: trend
          uri: lb://trend
          predicates:
            - Path=/trend/**

eureka:
  client:
    serviceURL:
      defaultZone: http://localhost:8761/eureka