1

根据文档,@EnableSidecar 注释充当希望在 Eureka 中注册的非 JVM 应用程序的代理。因此,要设置的配置是:

sidecar:
  port: 81 <-- Port of the non-JVM application
  health-uri: http://10.135.16.50:${sidecar.port}/api/health.php <-- URI of the non-JVM application's health endpoint
  home-page-uri: http://10.135.16.50:${sidecar.port}/

一旦“sidecar”启动并运行,我们应该能够通过服务注册表调用非 JVM 端点之一,只需使用“sidecar”应用程序用于在 Eureka 中注册的名称。因此,例如,如果我们的“sidecar”应用程序在 Eureka 中注册为“php-sidecar”,以代理具有以下端点的 PHP 应用程序:

http://10.135.16.50:81/api/microservice.php

然后我们应该能够调用以下端点来访问非 JVM 应用程序(假设“sidecar”在“localhost”和端口 8080 中):

http://localhost:8080/php-sidecar/api/microservice.php

但是,这并没有按预期工作。当我们请求上面的 URI 时,实际上发出了对“localhost:81”的请求,因为不知何故,“sidecar”正在获取它的主机 URI,而不是定义为 sidecar 属性的一部分的 home-page-uri。

如果我们使用 localhost 在本地运行非 JVM 应用程序,那么一切都会按预期工作,但这绝对不是现实的用例。

因此,我在配置中缺少什么来告诉 Spring Cloud(在这种特殊情况下为 Zuul)使用非 JVM 主页 URI 而不是我的本地主机 URI?

谢谢你的支持。

4

2 回答 2

1

经过一番研究,事实证明,sidecar 必须始终与非 JVM 应用程序部署在同一主机上。

于 2016-04-26T08:58:38.187 回答
0
After some research, it turns out that the sidecar must always be deployed in the same host as the non-JVM application.

不,您可以添加sidecar.ip-address = 10.135.16.50 到您的yaml配置文件

我正在使用 spring-boot-starter-parent 版本1.5.6.RELEASE 工作正常

于 2019-11-21T05:59:50.733 回答