为什么Spring Cloud @EnableSidecar使用@EnableCircuitBreaker

问题描述 投票:0回答:2

我在python中使用端口8004的应用程序,它有端点。我需要将它集成到微服务平台,该平台具有Eureka发现服务器端口8001,Spring Boot管理端口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 - >边车端口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。现在一切正常,并且在Spring Boot Admin中可以看到python-app。

我的两个问题:

  1. 如果边车默认不需要断路器,为什么@EnableSidecar@EnableCircuitBreaker?如果有一个sidecar实例和python-service的多个实例,这是有道理的。我有1:1 - 一个边车和一个python-app。如果python app不可用,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
2个回答
0
投票

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


0
投票

好吧,我通过将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中有断路器模式和功能的其他原因是什么?

© www.soinside.com 2019 - 2024. All rights reserved.