【问题标题】:Feign Client communication in predix (Cloud Foundry)predix 中的 Feign 客户端通信(Cloud Foundry)
【发布时间】:2018-03-19 13:56:37
【问题描述】:

我有 2 个使用 Netflix eureka 构建的微服务。他们使用假客户端进行通信。在我的本地环境中,假装客户端可以正常工作。但在 Predix(云代工厂)环境中,它们无法通信。 Feign 客户端总是给出连接超时错误。发现 feign 客户端尝试使用实例 ip 地址进行连接(我认为 feign 客户端使用内部 ip 地址)。有没有办法解决这个问题,可能是启用容器通信或使用公共 uri

编辑: 我设法通过更改主机名来获取公共网址,如下所示。

eureka:
 instance:
  hostname: ${vcap.application.uris[0]}

但在 eureka 服务器中它注册为 ${vcap.application.uris[0]}:[random port](如 xxxxxx.run.aws-usw02-pr.ice.predix.io:61142/yyy) 有没有办法删除那个随机端口。

【问题讨论】:

  • 您能提供更多信息吗?你在 Predix 中运行 feign 客户端吗?您的其他 2 个微服务在哪里运行?在 Predix 云中运行的微服务不应该被 IP 地址引用,因为 IP 经常变化。
  • @gstroup 抱歉回复延迟。是的,所有微服务和 feign 客户端都在 predix 中运行。我设法解决了 IP 地址问题。 (见编辑后的帖子)。但是应用程序仍然使用随机端口注册。

标签: cloud-foundry netflix-eureka service-discovery netflix-feign predix


【解决方案1】:

我们已经设法使用以下配置修复了 feign 客户端问题,

eureka:
  client:
    serviceUrl:
      defaultZone: https://someeurekaserver/eureka/
    registerWithEureka: true
    fetchRegistry: false
    healthcheck:
      enabled: true
  instance:
    hostname: ${vcap.application.application_uris[0]}
    instanceId: ${spring.application.name}:${random.int}
    secure-port: 443
    non-secure-port: 443
    secure-port-enabled: true
    non-secure-port-enabled: false
    preferIpAddress: false
    leaseRenewalIntervalInSeconds: 10
    home-page-url: https://${eureka.instance.hostname}:${eureka.instance.secure-port}
    secure-virtual-host-name: https://${vcap.application.application_uris[0]}

重要性配置为secure-virtual-host-name: https://${vcap.application.application_uris[0]}

【讨论】:

    【解决方案2】:

    目前无法将特定端口分配给在 Predix Cloud Foundry 中运行的应用程序。正如您所发现的,CF 分配了一个随机端口,但这仅在 CF 环境中使用。任何其他微服务/客户端/应用程序都应仅将端口 443 用于 HTTPS。所以,如果可能的话,也许你可以硬编码你的 Eureka 客户端来使用 443。

    【讨论】:

    • 是的,我将客户端端口硬编码为 443,但应用程序无法启动。我认为 443 帖子没有暴露在容器中。
    • 对不起,我可能把你弄糊涂了。因此,您的客户端将通过 443 访问其他服务。但在内部,CF 将为您的客户端分配不同的端口。所以这就是为什么你不能硬编码客户端(或任何使用特定端口的微服务)。你应该配置你的客户端以通过 443 与其他 CF 微服务通信。
    • 有没有一种方法可以通过容器 ip 和端口来启用容器之间的内部通信。因为现在 CF 分配容器端口。
    • 我们使用以下更改主机名将端口设置为 80: ${vcap.application.application_uris[0]} instanceId: ${spring.application.name}:${random.int} 安全-port-enabled: false non-secure-port-enabled: true secure-port: 443 non-secure-port: 80 health-check-url: https://${eureka.instance.hostname}:${eureka. instance.non-secure-port}/health status-page-url: https://${eureka.instance.hostname}:${eureka.instance.non-secure-port}/info home-page-url: https ://${eureka.instance.hostname}:${eureka.instance.non-secure-port} preferIpAddress: false
    猜你喜欢
    • 2020-01-27
    • 1970-01-01
    • 2017-01-22
    • 1970-01-01
    • 2015-02-22
    • 2021-10-22
    • 1970-01-01
    • 2018-07-11
    • 2021-11-18
    相关资源
    最近更新 更多