【问题标题】:@Loadbalanced - will it work with AsyncRestTemplate?@Loadbalanced - 它可以与 AsyncRestTemplate 一起使用吗?
【发布时间】:2017-09-14 20:21:06
【问题描述】:

我尝试关注“https://github.com/spring-cloud/spring-cloud-sleuth/issues/124”(https://github.com/spring-cloud-samples/brewery/blob/master/brewing/src/main/java/io/spring/cloud/samples/brewery/bottling/BottlingConfiguration.java#L30),但没有帮助。 loadBalancerInterceptor 未添加到 AsyncRestTemplate。 当我调试时,我发现拦截器是在创建所有 bean 之后“添加/注册”的 - 所以 AsyncRestTemplate 是在 RestTemplate 之后和 @Loadbalanced 拦截器被添加之前立即创建的。

【问题讨论】:

  • 你能把你的样本贴在某个地方吗?
  • 一个附加信息是:我有 2 个“@Loadbalanced”RestTemplates,我只想将其中一个传递给 AsyncRestTemplate(为此,我尝试使用“@Qualifier”并尝试指定名称对应于其中之一-两种方法均失败-未添加拦截器)。我现在将尝试给你一个示例项目。
  • 您是否尝试过自动装配拦截器列表并手动添加它们?一个样本真的很有帮助
  • 嗨 @MarcinGrzejszczak - 这是 Eureka 客户端项目的链接 - github.com/jot-hub/eureka-async-rest。需要设置 Eureka 服务器,并在 Eureka 客户端项目中更新 eureka url。
  • 您没有将 AsyncRestTemplate 包装在跟踪表示中。检查文档的这一部分 - cloud.spring.io/spring-cloud-sleuth/1.1.x/…(我昨天添加的)。

标签: spring-boot spring-cloud netflix-eureka spring-cloud-netflix


【解决方案1】:

您没有将 AsyncRestTemplate 包装在跟踪表示中。检查文档的这一部分 - cloud.spring.io/spring-cloud-sleuth/1.1.x/#_multiple_asynchronous_rest_templates(我昨天添加了它)。

更新:

此 PR https://github.com/spring-cloud/spring-cloud-commons/pull/149 完全在 Dalston 版本中修复了 AsyncRestTemplate 的问题。

【讨论】:

  • TraceAsyncRestTemplate 仍然没有确保 LoadBalancerInterceptor 被调用 - 即我继续从 Eureka 获得“UnknownHostException” - 我更新了项目 - github.com/jot-hub/eureka-async-rest
  • 我也在看github.com/spring-cloud/spring-cloud-commons/pull/149 - 这是实现相同目标的更直接的方法吗?
  • Spring cloud 的最新 Dalston 版本通过将 @LoadBalanced 支持也添加到 AsyncRestTemplate 来解决此问题 - 项目已更新此类更改(重要更改在 pom 中)- github.com/jot-hub/eureka -async-rest
  • 它适用于 Dalston 版本 - 独立于 TraceAsyncRestTemplate
猜你喜欢
  • 1970-01-01
  • 2011-08-15
  • 2018-02-16
  • 2020-06-30
  • 2014-11-15
  • 2011-12-07
  • 2011-11-20
  • 2011-06-02
  • 2012-04-16
相关资源
最近更新 更多