AWS ECS Zuul路由

问题描述 投票:1回答:1

我在AWS ECS上设置了Spring Cloud,但我遇到了Zuul / Eureka的问题。当我尝试命中端点“/ api / second / service2”时,我看到了这个错误:

引起:com.netflix.client.ClientException:负载均衡器没有客户端的可用服务器:service2

我在Eureka实例中使用弹性IP,如https://github.com/Netflix/eureka/wiki/Deploying-Eureka-Servers-in-EC2所述。我有2个春季启动应用程序,我在Eureka中看到它们。我可以直接点击端点。

这是Eureka服务器的配置:

server:
  port: 8761
eureka:
  client:
    fetchRegistry: false
    registerWithEureka: false
    eurekaServerURLContext: eureka
    region: eu-west-3
    eurekaServerPort: 8761
    useDnsForFetchingServiceUrls: true
    eurekaServerDNSName: my.dns
  datacenter: cloud

客服2:

spring:
  application:
    name: service2
server:
  port: 8882
eureka:
  datacenter: cloud
  instance:
    preferIpAddress: true
  client:
    fetchRegistry: true
    eurekaServerURLContext: eureka
    region: eu-west-3
    eurekaServerPort: 8761
    useDnsForFetchingServiceUrls: true
    eurekaServerDNSName: my.dns

Zuul:

pring:
  application:
    name: api-gateway
server:
  port: 8080
eureka:
  datacenter: cloud
  client:
    fetchRegistry: true
    eurekaServerURLContext: eureka
    region: eu-west-3
    eurekaServerPort: 8761
    useDnsForFetchingServiceUrls: true
    eurekaServerDNSName: my.dns

zuul:
  prefix: /api
  routes:
    first-service:
      path: /first/**
      serviceId: service1
    second-service:
      path: /second/**
      serviceId: service2

你知道问题出在哪里吗?

编辑:仅当我将service2实例端口从8882映射到端口80时才有效

amazon-web-services docker amazon-ecs netflix-eureka netflix-zuul
1个回答
0
投票

我可以看到你的service2没有在eureka注册,例如:

eureka:
  client:
    registerWithEureka: true

不需要其余的配置,那些是eureka服务器的配置,你不应该在任何服务中配置eureka服务器,它是在eureka服务本身完成的。

它应该获取注册表,所以在service2你会有

spring:
  application:
    name: service2
server:
  port: 8882
eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true

其他服务也是如此

© www.soinside.com 2019 - 2024. All rights reserved.