gpt4 book ai didi

java - 为什么Spring Cloud @EnableSidecar使用@EnableCircuitBreaker

转载 作者:行者123 更新时间:2023-12-02 06:11:42 25 4
gpt4 key购买 nike

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

我有两个选择:

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

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

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

漂亮,而且有效。当我打开 Eureka web-ui 时,所有服务都在那里。当我打开 Spring Boot 管理 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 - 一个 sidecar 和一个 python-app。如果 python 应用程序不可用,sidecar 应该返回错误。我不需要断路器吗?还是我呢?

  2. 为什么注解@EnableSidecar会影响Spring Boot客户端,因此它不会显示在Spring Boot管理UI上。我认为存在错误,或者如何在 Spring Boot Admin web-ui 中启用 sidecar 进行监控。

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

最佳答案

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

关于java - 为什么Spring Cloud @EnableSidecar使用@EnableCircuitBreaker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55902559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com