【问题标题】:Why does Spring Cloud @EnableSidecar use @EnableCircuitBreaker为什么 Spring Cloud @EnableSidecar 使用 @EnableCircuitBreaker
【发布时间】:2019-04-29 11:38:05
【问题描述】:

我在 python 中有一个使用端口 8004 的应用程序,它有端点。我需要将它集成到微服务平台中,该平台有 Eureka 发现服务器端口 8001,Spring Boot Admin 端口 8002,网关端口 80。网关使用 Zuul 代理,它将请求转发到所需的服务。

我有两个选择:

  1. 更改我的 python-app 的代码,使其可以拥有 Spring Cloud 服务的端点
  2. 或者使用 Spring Cloud Sidecar - 它实现了这些端点。 https://cloud.spring.io/spring-cloud-netflix/multi/multi__polyglot_support_with_sidecar.html

我决定有边车。 Sidecar 端口 8003,python-app 端口 8004。@EnableSidecar 注释 + @EnableDiscoveryClient - 和魔术。然后我需要添加网关配置以将请求转发到 python-service。而且我需要配置 sidecar Zuul Proxy,所以它将请求转发到 python 应用程序。

网关端口 80 -> sidecar 端口 8003 -> python-app 端口 8004。

很漂亮,而且有效。当我打开 Eureka web-ui 时,所有服务都在那里。当我打开 Spring Boot Admin UI 时,它说 python-service(它的 sidecar)已关闭。

Spring Boot Admin客户端(sidecar端配置),端口为28003,与sidecar不同。

management:
  server:
    port: 18003
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: ALWAYS

我用@EnableZuulProxy 替换了@EnableSidecar。现在一切正常,python-app 在 Spring Boot Admin 中可见。

我的两个问题:

  1. 如果sidecar默认不需要断路器,为什么@EnableSidecar@EnableCircuitBreaker?如果有一个 sidecar 实例和多个 python-service 实例,这是有意义的。我有 1:1 - 一个边车和一个 python-app。如果 python 应用程序不可用,sidecar 应该返回一个错误。我不需要断路器?还是我?

  2. 为什么注解@EnableSidecar会影响Spring Boot客户端,所以在Spring Boot Admin UI上不显示。我认为有一个错误或如何在 Spring Boot Admin web-ui 中启用 sidecar 监控。

Spring Boot 版本是 2.0.7,Spring Cloud 版本是 2.0.0

【问题讨论】:

    标签: java spring-boot spring-cloud spring-boot-admin circuit-breaker


    【解决方案1】:

    sidecar 不应将请求代理到非 jvm 服务中。它使用 java eu​​reka 客户端代表非 jvm 服务进行注册。然后非 jvm 服务可以使用 sidecar 中嵌入的 zuul 向其他服务发出请求。它不需要了解 eureka、hystrix(断路器)或ribbon(客户端负载均衡器),但这是可选的。

    【讨论】:

    • 如果sidecar下的应用需要访问平台中的其他服务,同意。但是,如果用户提出请求,网关通过 sidecar 将其转发给应用程序,该怎么办?
    • 它不是为此而生的
    【解决方案2】:

    嗯,我通过将 Spring Cloud 升级到 2.1.1-RELEASE 解决了这个问题。 然后我又遇到了一个问题。

    Field restTemplate in org.springframework.cloud.netflix.sidecar.LocalApplicationHealthIndicator required a single bean, but 3 were found
    

    为了修复它,我添加了配置

    @Configuration
    public class RestTemplateConfig {
    
        @Primary
        @Bean
        public RestTemplate restTemplate() {
            return new RestTemplate();
        }
    }
    

    从逻辑的角度来看,sidecar 应该将请求转发给应用程序。使用 Hystrix,它不会等待及时响应,而是更快地失败。在 Sidecar 中具有断路器模式和功能的其他原因是什么?

    【讨论】:

      猜你喜欢
      • 2020-08-02
      • 2022-09-30
      • 2021-10-25
      • 1970-01-01
      • 2018-10-22
      • 1970-01-01
      • 2021-03-11
      • 2019-09-29
      • 1970-01-01
      相关资源
      最近更新 更多