标签: hystrix

怎么电路又闭合了?

我正在尝试了解 Hystrix。我了解当服务调用 3rd 方服务并且该服务没有响应并且阈值已超过配置时,电路将被打开并且继续呼叫将被短路。

但我无法理解电路是如何再次闭合的。让我们假设我们的服务正在调用 3rd 方服务,并且该服务无法正常工作,因此电路已打开。5 分钟后,该服务开始正常工作,现在电路应该关闭。调用服务如何知道第 3 方服务已经开始正常运行,现在应该关闭?

architecture hystrix microservices

6
推荐指数
1
解决办法
2155
查看次数

将 HystrixCommands 迁移到 Resilience4j

鉴于 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

java reactive-programming hystrix rx-java2 resilience4j

6
推荐指数
1
解决办法
3543
查看次数

com.netflix.zuul.exception.ZuulException:Hystrix 读取超时

我正在尝试使用 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

6
推荐指数
3
解决办法
1万
查看次数

Hystrix 的请求折叠替代方案

Netflix 将 Hystrix 正式置于维护模式(https://github.com/Netflix/Hystrix#hystrix-status),我开始寻找替代方案。当涉及到断路器、隔板、重试等模式时,有一些不错的库,例如resilience4j,但我找不到 Hystrix 可以做的请求崩溃的替代方案。

有人知道可以提供此类功能的库吗?

谢谢,本杰明

cloud hystrix resiliency microservices resilience4j

6
推荐指数
1
解决办法
997
查看次数

为单个 Feign 客户端禁用 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)

java spring-boot hystrix spring-cloud-feign

6
推荐指数
1
解决办法
1414
查看次数

BeanCreationException:创建类路径资源中定义的名为“configurationPropertiesBeans”的 bean 时出错

我正在为断路器编写一个小程序,运行该应用程序时会抛出异常。
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]

Pom.xml

<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)

java spring spring-boot hystrix

6
推荐指数
2
解决办法
3万
查看次数

用于Java中断路器的Hystrix配置

我正在写一个应用程序,我想实现断路器模式.这是我写的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)

我无法理解如何配置线程数,断路器的阈值时间和要处理的请求数.

java netflix circuit-breaker hystrix

5
推荐指数
2
解决办法
1万
查看次数

如何通过JMX公开Hystrix的断路器状态

我一直在寻找关于如何在JMX上公开Hystrix断路器状态的教程.我刚刚发现了一个用于公开指标(例如计数器,仪表等)的API hystrix-servo-metrics-publisher.

是否可以在JMX上公开断路器状态?

java jmx hystrix

5
推荐指数
1
解决办法
1869
查看次数

HystrixCommand仅适用于Spring Service或Component吗?

Spring Hystrix是否仅与@Service和@Component一起使用?

我有一个定义为@RestController的类,并且我的HystrixCommand无法启动,该方法可以执行,但不能充当HystrixCommand。当我创建一个@Service类并放入HystrixCommand方法并回退到其中时,HystrixCommand将正常运行。

可与@EnableHystrix一起使用的适当的Spring注释是什么?

spring netflix hystrix spring-cloud

5
推荐指数
1
解决办法
1144
查看次数

spring cloud stream'bindingService'错误

我正在尝试实施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

5
推荐指数
2
解决办法
1万
查看次数