【问题标题】:Spring cloud config client without Eureka, Ribbon and spring boot没有 Eureka、Ribbon 和 Spring Boot 的 Spring Cloud 配置客户端
【发布时间】:2017-01-02 15:14:35
【问题描述】:

我在 AWS 中运行了 Spring Web 应用程序(不是 Spring Boot)。我正在尝试创建集中式配置服务器。更改属性后如何刷新spring-cloud-client?根据教程

通过向客户端的刷新端点 http://localhost:8080/refresh 发送一个空的 HTTP POST 来执行执行器端点,然后通过查看 http://localhost:8080/message 端点来确认它是否有效。

但我的 aws Ec2 实例位于负载均衡器后面,因此我无法调用客户端 URL。我不太了解 netflix Eureka 和 Ribbon,但似乎在客户端添加了另一个级别的负载均衡器。我不喜欢这种方法。只是为了改变一个属性,我不想让现有项目变得不必要地复杂。还有其他方法吗?还是我误解了 Eureka/Ribbon 的用法?

我看过spring-cloud-config-client-without-spring-bootspring-cloud-config-client-without-auto-configuration 他们都没有答案。第一个帖子在 2015 年得到回答。想知道有什么更新吗?

【问题讨论】:

  • Eureka 和 Ribbon 与配置客户端无关。有一个 HTTP api 来配置服务器,但它仍然是你必须在非启动客户端上实现的东西。
  • @spencergibb 你能解释一下 Http Api 吗?或提供参考链接?客户端如何刷新属性变化?

标签: spring spring-cloud spring-cloud-config


【解决方案1】:

从配置服务器获取配置属性。你可以做一个http请求。示例:

从文档中我们可以看到:

/{application}/{profile}[/{label}]
/{application}-{profile}.yml <- example
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties

因此,如果您向http://localhost:8080/applicationName-activeProfile.yml 发出请求,您将收到具有该名称和活动配置文件的应用程序的 .yml 格式的属性。 Spring Boot 配置客户端会自动提供这些值,但您必须手动提供这些值。

你不需要 Eureka/Ribbon 来工作,它是一个单独的组件。 更多信息:http://cloud.spring.io/spring-cloud-static/spring-cloud.html#_spring_cloud_config

也许你甚至可以使用 spring-cloud-config 但我不确定没有 spring-boot 需要什么额外的配置。 https://cloud.spring.io/spring-cloud-config/

【讨论】:

  • @spencergibb 感谢您的解释。如果 spring boot 自动刷新属性,活动请求会发生什么?
  • 主动请求什么?
  • @spencergibb 如果我在负载均衡器后面有 3 个实例,并且负载均衡器是已公开的 URL,如果我在客户端调用 refresh api,它将在三个实例之一上触发它。不是全部三个。我应该怎么做才能确保我可以刷新每个实例。
猜你喜欢
  • 2015-12-12
  • 2016-04-15
  • 1970-01-01
  • 2019-09-18
  • 1970-01-01
  • 2015-04-11
  • 2016-06-21
  • 2019-04-24
  • 2017-11-23
相关资源
最近更新 更多