标签: hystrix

将 Hystrix 与 Spring 数据存储库结合使用

鉴于 Spring Data 和相关 REST 存储库的主要好处之一是大多数时候开发人员不必担心底层实现,是否有一种开箱即用的方式来利用 Spring Cloud Netflix 库,特别是本例中的 Hystrix 注释,无需扩展所提供的存储库接口中的每个调用或创建我自己的实现?

spring-data spring-data-rest hystrix spring-cloud

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

当 Hystrix 短路且电路开路时,即使有问题的服务备份,它也永远不会关闭

我遇到一个问题,当 hystrix 断路器跳闸时,它不会再次关闭。我已将日志记录转为调试,并且我没有看到它试图允许测试请求通过,在这种情况下,在我看来它永远不会关闭,因为它只有在测试执行成功完成时才应该关闭,表明有问题的服务现在是健康。根据文档,断路器配置默认值应该可以工作,但我似乎无法说出为什么测试请求永远不会被允许通过。

2016-02-18 09:00:38,782 noodle-soup-service application-akka.actor.default-dispatcher-7 ERROR akka.actor.OneForOneStrategy - CallServiceCommand short-circuited and fallback failed.
com.netflix.hystrix.exception.HystrixRuntimeException: CallServiceCommand short-circuited and fallback failed.
    at com.netflix.hystrix.AbstractCommand$16.call(AbstractCommand.java:816) ~[com.netflix.hystrix.hystrix-core-1.4.23.jar:1.4.23]
    at com.netflix.hystrix.AbstractCommand$16.call(AbstractCommand.java:790) ~[com.netflix.hystrix.hystrix-core-1.4.23.jar:1.4.23]
    at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$1.onError(OperatorOnErrorResumeNextViaFunction.java:99) ~[io.reactivex.rxjava-1.1.0.jar:1.1.0]
    at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:71) ~[io.reactivex.rxjava-1.1.0.jar:1.1.0]

...

Caused by: java.lang.RuntimeException: Hystrix circuit short-circuited and is OPEN
    at com.netflix.hystrix.AbstractCommand$1.call(AbstractCommand.java:414) ~[com.netflix.hystrix.hystrix-core-1.4.23.jar:1.4.23]
    ... 38 common frames omitted
Run Code Online (Sandbox Code Playgroud)

java scala akka hystrix

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

Spring Boot 2 - 从 RestControler 返回 rx.Observable

我试图从 Spring RestController 返回一个 Observable,但没有成功。我的代码如下:

@RestController
public class HystrixCommentController {

    @GetMapping(value = "/com1/{id}")
    public Observable<Comment> getComment1(@PathVariable int id) {
        return Observable.just(new Comment());
    }
}
Run Code Online (Sandbox Code Playgroud)

在邮递员中运行请求时,我总是收到以下错误:

{
  "timestamp": "2018-07-08T16:07:36.809+0000",
  "status": 500,
  "error": "Internal Server Error",
  "message": "No converter found for return value of type: class rx.internal.util.ScalarSynchronousObservable",
  "path": "/com1/1"
}
Run Code Online (Sandbox Code Playgroud)
  • SpringBoot 2 不也像 Mono/Flux 一样支持 RestController 中的 rx.Observable 吗?

  • 我需要手动将 Observable 转换为 Mono/Flux 吗?

问候

注意:spring-boot-starter-webflux 包含在 pom 中

我试过这个:

@RestController
    public class HystrixCommentController {

        @GetMapping(value = "/com1/{id}", produces = "application/json")
            public …
Run Code Online (Sandbox Code Playgroud)

spring spring-mvc rx-java spring-boot hystrix

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

如何访问hystrix仪表板?

我在 Spring Boot 应用程序中添加了以下依赖项:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
    <version>2.1.3.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

并用以下标记配置类:

@EnableHystrixDashboard
@EnableHystrix
Run Code Online (Sandbox Code Playgroud)

我尝试访问http://localhost:8080/hystrix (我也尝试过http://localhost:8081/hystrix

我看到:

白标错误页面 此应用程序没有明确的 /error 映射,因此您将其视为后备。

Mon Nov 11 21:47:56 MSK 2019 出现意外错误(类型=未找到,状态=404)。没有可用的消息

在启动期间,我看到以下消息:

2019-11-11 21:43:17.724  INFO 15912 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-11-11 21:43:22.581  INFO 15912 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-11-11 21:43:23.362  INFO 15912 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8081 (http)
2019-11-11 …
Run Code Online (Sandbox Code Playgroud)

java spring-boot hystrix spring-cloud spring-cloud-netflix

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

Istio 断路器回退

我正在探索 Istio 的断路器,如果电路跳闸,我不想设置回退方法。

我有一些 Spring Boot 应用程序部署在 kubernetes 上,并且在 DestinationRule 中定义了 Istio 的断路。

我可以看到,当我故意关闭被调用的服务时,我的调用方应用程序会收到 503 Service Unavailable 异常。

我正在寻找设计模式或库,我可以使用它们为我的休息调用定义回退方法,类似于@HystrixCommand。

我检查了spring-cloud-circuitBreaker但它不支持 Istio。我还使用 Spring RestTemplate 探索了 ClientHttpRequestInterceptor,并且可以捕获所有 ServiceUnavailable 异常,但是我需要一种方法来为不同的 REST 调用配置不同的回退方法。

任何建议表示赞赏。

circuit-breaker spring-boot hystrix istio

5
推荐指数
0
解决办法
373
查看次数

是否可以订阅Hystrix中的CircuitBreaker开幕活动?

对于单元测试,我希望能够订阅Hystrix事件,特别是当断路器打开或关闭时会发生事件.我环顾四周寻找示例,看来解决方案是利用指标流并监控断路器标志.

由于Hystrix是基于RxJava构建的,我认为应该有某个事件的订阅接口.有没有简单的方法在Hystrix中订阅这些类型的事件?

谢谢!

java hystrix

4
推荐指数
1
解决办法
1412
查看次数

Feign Hystrix 命令名称不起作用

如果我只是将 Hystrix 命令定义为类,我可以控制定义组键和命令键,如下所示。

     private static class MyHystrixCommand extends HystrixCommand<MyResponseDto> {
               public MyHystrixCommand() {
        super(HystrixCommandGroupKey.Factory.asKey("MyHystrixGroup"));
     }
Run Code Online (Sandbox Code Playgroud)

所以上面的代码组key是MyHystrixGroup,Command Key是MyHystrixCommand。

如果我想设置这个 hystrix 命令的任何配置,我可以这样做

      ConfigurationManager.getConfigInstance().setProperty(
                                "hystrix.command.MyHystrixCommand.execution.timeout.enabled", false); 
Run Code Online (Sandbox Code Playgroud)

默认情况下,

       ConfigurationManager.getConfigInstance().setProperty(
                "hystrix.command.default.execution.timeout.enabled", false);
Run Code Online (Sandbox Code Playgroud)

现在,当我使用 Feign Hystrix 时,我没有定义命令名称/组名称。根据此处的文档,组键与目标名称匹配,命令键与日志键相同。

所以如果我有一个这样的 FeignClient,

     interface TestInterface {
        @RequestLine("POST /")
        String invoke() throws Exception;
     }
Run Code Online (Sandbox Code Playgroud)

我在工厂类中创建了我的 Feign 客户端的实例。

   class TestFactory {

    public TestInterface newInstance() {

        ConfigurationManager.getConfigInstance()
            .setProperty("hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds", 500);

        return HystrixFeign.builder()
            .target(TestInterface.class, "http://localhost:" + server.getPort(), (FallbackFactory) new FallbackApiRetro());
    }

 }
Run Code Online (Sandbox Code Playgroud)

正如你在返回客户端之前看到的,我想设置我的 hystrix 命令的超时配置。

我正在用 MockWebServer 测试它。

  @Test
public void fallbackFactory_example_timeout_fail() throws …
Run Code Online (Sandbox Code Playgroud)

java web-services hystrix feign

4
推荐指数
1
解决办法
1365
查看次数

为什么hystrix或任何其他用于微服务的断路器?

我正在开发带有弹簧靴和弹簧云的微服务.我开始了解hystrix和断路器模式.我知道断路器用于响应备用响应,以防下游微服务器出错,我依赖它来获取数据.我的问题是,如果我没有提供任何有意义的替代响应,为什么我需要一个断路器呢?

java spring spring-boot hystrix microservices

4
推荐指数
1
解决办法
1283
查看次数

使用环境变量设置Hystrix超时

要更改Hystrix的默认请求超时(1000毫秒),必须设置以下属性: hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=2000

相应的环境变量是什么?

我想在我最喜欢的云平台上"调整"超时,而不首先触及源代码.我很确定这个不起作用:HYSTRIX_COMMAND_DEFAULT_EXECUTION_ISOLATION_THREAD_TIMEOUT_IN_MILLISECONDS=2000


编辑:Spring Cloud Camden/Spring Boot 1.4发现问题.

hystrix spring-cloud spring-cloud-netflix

4
推荐指数
2
解决办法
7076
查看次数

Spring Boot 2 - 将 Mono 转换为 rx.Observable?

我正在尝试将 HystrixObservableCommand 与 Spring WebFlux WebClient 一起使用,我想知道是否有一个“干净”的方法可以将 Mono 转换为 rx.Observable。我的初始代码如下所示:

public Observable<Comment> getComment() {

    return webClient.get()
            .uri(url)
            .accept(MediaType.APPLICATION_JSON)
            .retrieve()
            .bodyToMono(Comment.class)
            // stuff missing here :(.
}
Run Code Online (Sandbox Code Playgroud)

有一个简单的方法可以做到这一点吗?

问候

spring spring-mvc rx-java spring-boot hystrix

4
推荐指数
1
解决办法
2346
查看次数