[英]resilience4j bulkhead skipping fallback method for certain type of exceptions
我使用 reslience4j 隔板将活动线程数限制为我的一种服务方法。 当线程限制超过配置时,它应该 go 到按预期发生的回退方法。
但是,当验证失败时,作为我方法中业务逻辑的一部分,我会向我的消费者抛出带有自定义消息的 BadRequestException。 当checkedException也发生时,这里的控件转到一个回退方法理想情况下不应该是这样。
那么我们是否有任何配置来跳过某些类型的异常的控制转到后备方法,类似于我们在 Hystrix 中的方式?
@Bulkhead(name="bhName" fallbackMethod="fallbackMethod")
public void doSomething(){
//validatiion
// if validation succeeds
//do some business logic
// else if validation fails
throw BadRequestException("Error Message")
}
public void fallbackMethod(Exception ex){
log.info("The number of concurrency limit exceeded");
return null;
}
我使用 reslience4j 隔板将活动线程数限制为我的一种服务方法。 当线程限制超过配置时,它应该转到按预期发生的回退方法。
但是作为我方法中业务逻辑的一部分,当验证失败时,我将带有自定义消息的 BadRequestException 抛出给我的消费者。 这里,当checkedException也发生过时,控件将转为一个后备方法。理想情况下,情况并非如此。
那么,我们是否有任何配置可以跳过对某些类型的Exception的控制权转为fallback方法,类似于我们在Hystrix中的方式?
@Bulkhead(name="bhName" fallbackMethod="fallbackMethod")
public void doSomething(){
//validatiion
// if validation succeeds
//do some business logic
// else if validation fails
throw BadRequestException("Error Message")
}
public void fallbackMethod(Exception ex){
log.info("The number of concurrency limit exceeded");
return null;
}
我认为最新的 Spring Boot 和 Spring Cloud 版本存在问题。 我测试了旧的,并且 Bulkhead 模式对我有用。
请检查我的 Maven POM。
添加以下 Spring 引导版本
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.3.RELEASE</version>
<relativePath/>
</parent>
添加以下 Spring Cloud and Resilience4j library version
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR1</spring-cloud.version>
<resilience4j.version>1.5.0</resilience4j.version>
</properties>
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-spring-boot2</artifactId>
<version>${resilience4j.version}</version>
</dependency>
添加以下依赖项
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-circuitbreaker</artifactId>
<version>${resilience4j.version}</version>
</dependency>
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-timelimiter</artifactId>
<version>${resilience4j.version}</version>
</dependency>
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-bulkhead</artifactId>
<version>${resilience4j.version}</version>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.