我正在尝试了解 Hystrix。我了解当服务调用 3rd 方服务并且该服务没有响应并且阈值已超过配置时,电路将被打开并且继续呼叫将被短路。
但我无法理解电路是如何再次闭合的。让我们假设我们的服务正在调用 3rd 方服务,并且该服务无法正常工作,因此电路已打开。5 分钟后,该服务开始正常工作,现在电路应该关闭。调用服务如何知道第 3 方服务已经开始正常运行,现在应该关闭?
鉴于 Hystrix 进入维护模式,我一直致力于将(相当大的)代码库迁移到 Resilience4j。
我在 Hystrix 中大量使用以下模式:
new HystrixCommand<SomeReturnValue>(DependencyKeys.DEPENDENCY) {
@Override
protected SomeReturnValue run() {
return someExpensiveCall();
}
}
.observe()
Run Code Online (Sandbox Code Playgroud)
我想用 Resilience4j 复制 Hystrix 的一些功能。
到目前为止,我有以下语法来连接外部调用:
resilience.single(DependencyKeys.DEPENDENCY, this::someExpensiveCall);
Run Code Online (Sandbox Code Playgroud)
其中Resilience
类提供single
方法:
public <T> Single<T> single(ResilienceKey key, Callable<T> callable) {
return Completable.complete()
.subscribeOn(Schedulers.computation())
.observeOn(configuration.scheduler(key))
.andThen(Single.defer(() -> Single.fromCallable(callable)
.lift(CircuitBreakerOperator.of(configuration.circuitBreaker(key)))
.lift(RateLimiterOperator.of(configuration.rateLimiter(key)))
.lift(BulkheadOperator.of(configuration.bulkhead(key)))
))
.observeOn(Schedulers.computation());
}
Run Code Online (Sandbox Code Playgroud)
在断路和在不同线程池上运行代码方面,这看起来如何更好地类似于 Hystrix,但以更理智的方式。我真的不喜欢用 just 来启动链,这样我就可以在实际的可调用对象被包装之前Completable.complete()
强制使用 a 。observeOn
我正在尝试使用 eureka 和 zuul 进行微服务。并且所有请求都存在问题,耗时超过 1 秒。据我了解,1 秒是默认的 hystrix 超时,为了在 Zuul 中配置超时,我必须配置这些属性:
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds
ribbon.ConnectTimeout
ribbon.ReadTimeout
但是当我设置它们时,Intelije Idea 中的每一个都有“无法解析配置属性......”警告。而且,它们似乎没有被应用,也不起作用。
spring-boot hystrix netflix-eureka netflix-zuul netflix-ribbon
Netflix 将 Hystrix 正式置于维护模式(https://github.com/Netflix/Hystrix#hystrix-status),我开始寻找替代方案。当涉及到断路器、隔板、重试等模式时,有一些不错的库,例如resilience4j,但我找不到 Hystrix 可以做的请求崩溃的替代方案。
有人知道可以提供此类功能的库吗?
谢谢,本杰明
我的 SpringBoot 应用程序启用了 Hystrix,并为某些 Feign 客户端定义了回退,其余客户端未定义。
现在,我想为尚未定义回退的那些禁用 Hystrix。因此,我按照 [第 7.4 段] https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-feign.html 中列出的步骤操作,即使用 vanilla Feign.Builder 创建单独的 Feign 配置. 但是,添加新的 @Bean Feign.Builder 会禁用我不想要的所有 Feign 客户端的 Hystrix 功能。如果我删除@Bean Feign.Builder,Hystrix 回退会像往常一样在 myhystrixclient 中启动。一个类似的问题在这里如何在多个假客户端之一中禁用 hystrix仍然是开放的。我究竟做错了什么?
public class MyFeignClientConfiguration {
@Bean
public FeignErrorDecoder feignErrorDecoder() {
return new FeignErrorDecoder();
}
@Bean
@Scope("prototype")
public Feign.Builder feignBuilder() {
return Feign.builder();
}
}
Run Code Online (Sandbox Code Playgroud)
我的 Feign 客户端如下所示:
@FeignClient(name = "myregularclient", configuration = MyFeignClientConfiguration.class)
public interface MyRegularClient {
//my APIs here
}
Run Code Online (Sandbox Code Playgroud)
我的 Hystrix Feign 配置如下所示:
public class …
Run Code Online (Sandbox Code Playgroud) 我正在为断路器编写一个小程序,运行该应用程序时会抛出异常。
springboot 版本 2.5.4,Hystrix 版本使用2.2.6
BeanCreationException:创建类路径资源 [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class] 中定义的名为“configurationPropertiesBeans”的 bean 时出错:合并 bean 定义的后处理失败;嵌套异常是 java.lang.IllegalStateException:无法从 ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@659e0bfd] 内省类 [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans]
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.ramgovindhare</groupId>
<artifactId>cricuitbreakerhystrix</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>CricuitBreakerHystrix</name>
<description>firstMicroserviceProject</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-hystrix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.2.8.RELEASE</version> <--- **See this**
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> …
Run Code Online (Sandbox Code Playgroud) 我正在写一个应用程序,我想实现断路器模式.这是我写的Hystrix Command类:
public class HystrixCommandNextGen extends HystrixCommand<ScriptContext> {
private ScriptContext scriptctx;
private ScriptFactory scriptFactory;
private ScriptContext responseContext = null;
private Logger logger = LoggerFactory.getLogger(HystrixCommandNextGen.class);
public HystrixCommandNextGen(ScriptContext scriptctx, ScriptFactory scriptFactory) {
super(
Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("Thread_Pool"))
.andCommandKey(HystrixCommandKey.Factory.asKey(scriptctx.getExecutionData(ExecutionParam.SCRIPTNAME)))
);
this.scriptctx = scriptctx;
this.scriptFactory = scriptFactory;
HystrixCommandProperties.Setter().withCircuitBreakerEnabled(true);
HystrixCommandProperties.Setter().withCircuitBreakerRequestVolumeThreshold(150);
}
@Override
protected ScriptContext run() throws Exception {
scriptFactory.execute(scriptctx);
return scriptctx;
}
@Override
protected ScriptContext getFallback() {
logger.error("FI is not responding: Error occurred in the execution of " + getClass().getSimpleName());
return scriptctx;
}
}
Run Code Online (Sandbox Code Playgroud)
我无法理解如何配置线程数,断路器的阈值时间和要处理的请求数.
我一直在寻找关于如何在JMX上公开Hystrix断路器状态的教程.我刚刚发现了一个用于公开指标(例如计数器,仪表等)的API hystrix-servo-metrics-publisher
.
是否可以在JMX上公开断路器状态?
Spring Hystrix是否仅与@Service和@Component一起使用?
我有一个定义为@RestController的类,并且我的HystrixCommand无法启动,该方法可以执行,但不能充当HystrixCommand。当我创建一个@Service类并放入HystrixCommand方法并回退到其中时,HystrixCommand将正常运行。
可与@EnableHystrix一起使用的适当的Spring注释是什么?
我正在尝试实施Turbine AMQP来整合从多个服务到Hystrix Dashboard的所有流.
所以我在gradle文件中添加了几个依赖项,之后由于某种原因我无法启动我的应用程序.
来自启动的LOGS,我看到异常.
[LogMessage=Application startup failed]
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bindingService' defined in class path resource [org/springframework/cloud/stream/config/ChannelBindingServiceConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 1 of type [org.springframework.cloud.stream.binder.BinderFactory]: Error creating bean with name 'binderFactory' defined in class path resource [org/springframework/cloud/stream/config/BinderFactoryConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.cloud.stream.binder.BinderTypeRegistry]: Error creating bean with name 'binderTypeRegistry' defined in class path resource [org/springframework/cloud/stream/config/BinderFactoryConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed …
Run Code Online (Sandbox Code Playgroud) turbine spring-boot hystrix spring-cloud spring-cloud-stream
hystrix ×10
java ×5
spring-boot ×4
netflix ×2
resilience4j ×2
spring ×2
spring-cloud ×2
architecture ×1
cloud ×1
jmx ×1
netflix-zuul ×1
resiliency ×1
rx-java2 ×1
turbine ×1