java - 当我用 @HystrixCommand 标记方法时,出现 ReactiveException : java. lang.InterruptedException

标签 java spring-boot hystrix interrupted-exception circuit-breaker

我有以下方法:

    @Timed(value = "my.request.timer", percentiles = {0.5, 0.95}, histogram = true)
    public ResponseEntity<MyResponseDto> executeHttpCall(MyReq myReq) {
        log.warn("!!!!! REAL METHOD!!!! for {}", myReq);
        Mono<ResponseEntity<MyResponseDto>> responseEntityMono = webClient.post()
                .bodyValue(myReq)
                .retrieve()
                .toEntity(MyResponseDto.class);
        try {
            return responseEntityMono.block();
        } catch (Exception e) {
            log.warn("EXCEPTION: ", e);
        }
        return null;
    }

我想为该方法添加 hystrix,所以我得到了以下内容:

   @HystrixCommand(fallbackMethod = "nullResponse",
        threadPoolProperties = {
                @HystrixProperty(name = "coreSize", value = "1000"),
               @HystrixProperty(name = "maxQueueSize", value = "7777"),
        })
   @Timed(value = "my.request.timer", percentiles = {0.5, 0.95}, histogram = true)
    public ResponseEntity<MyResponseDto> executeHttpCall(MyReq myReq) {
        log.warn("!!!!! REAL METHOD!!!! for {}", myReq);
        Mono<ResponseEntity<MyResponseDto>> responseEntityMono = webClient.post()
                .bodyValue(myReq)
                .retrieve()
                .toEntity(myResponseDto.class);
        try {
            return responseEntityMono.block();
        } catch (Exception e) {
            log.warn("EXCEPTION: ", e);
        }
        return null;
    }

public ResponseEntity<MyResponseDto> nullResponse(MyReq myReq) {
    log.warn("Fallback method invoked for {}", myReq);
    fallbackMethodIvocationCount.increment();
    return null;
}

这成为错误的原因(有时会重现,有时则不会)

2019-11-11 17:33:51.954  WARN 2996 --- [ConnectorImpl-9] b.m.a.p.MyDetectorAPIConnectorImpl : EXCEPTION: 

2019-11-11 17:33:51.954  WARN 2996 --- [ConnectorImpl-9] b.m.a.p.MyDetectorAPIConnectorImpl : EXCEPTION: 

reactor.core.Exceptions$ReactiveException: java.lang.InterruptedException
    at reactor.core.Exceptions.propagate(Exceptions.java:336)
    at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:85)
    at reactor.core.publisher.Mono.block(Mono.java:1663)
    at my.MyService.executeHttpCall(MyDetectorAPIConnectorImpl.java:89)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)

此问题的原因是什么以及如何解决?

最佳答案

这是因为 hystrix 默认超时。可以禁用此超时以使用以下属性:

hystrix.command.default.execution.timeout.enabled: false

关于java - 当我用 @HystrixCommand 标记方法时,出现 ReactiveException : java. lang.InterruptedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58803556/

相关文章:

java - 如何在 ftp4j 库中使用 SSL

java - 在 spring boot 中重新加载/刷新缓存

java - Feign Hystrix 命令名称不起作用

java - Android CameraX 裁剪 media.Image?

java - ArrayList 重复删除

java - apollo-android可以作为java客户端使用吗?

java - 如何以 ManyToMany (RDBMS) 的形式加入两个集合 spring-data-mongodb

java - Hystrix 中命令指标更新延迟?

spring-boot - Hystrix 和 Turbine 不适用于 Spring boot 2 和 Spring cloud Finchley.M8

java - 在自定义 Java 组件上正确查找帧速率