java - Zuul无法路由到在 Eureka 服务器中注册的应用程序

标签 java spring-boot microservices netflix-eureka netflix-zuul

我正在开发一个微服务,我试图使用 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]

Zuul应用程序.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 代理导航到应用程序。

enter image description here

最佳答案

经过一些研究,我发现 Ribbon、Zuul 处于维护模式,我们不会得到任何新版本,Spring 也为 Ribbon、Zuul 等提供了替代方案。请参阅此链接 spring alternative用于负载平衡、代理服务器等

对于这个问题,我使用了 spring cloud gateway 而不是 Zuul,这是 spring 提供的替代方案

所需的依赖项

        <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

关于java - Zuul无法路由到在 Eureka 服务器中注册的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71195587/

相关文章:

spring - 有没有办法跳过仅针对特定作业的 Spring Batch 持久元数据?

javascript - 如何通过 AJAX 从 React 应用程序内的外部服务加载 React 组件

java - Apache Camel - 从主体中获取属性值

java - 在 Java 中存储颜色 - byte;byte;byte vs. byte[3] vs int

java - JMVTI :Could not find agent library

java - 在 OpenShift 上托管时无法找到 apache 公共(public)上传库

java - 特定查询错误 - SQLite Android

java - Spring Integration DSL 自定义错误 channel 与执行器的问题

spring - 使用 Spring Framework 和 Chrome 设置视频流

authentication - 如何跨不同 API 对 JSON Web token (JWT) 进行身份验证?