- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
按照入门指南 ( https://resilience4j.readme.io/docs/getting-started-3 ) 和演示项目 ( https://github.com/resilience4j/resilience4j-spring-boot2-demo ),我想通过自己创建一个更简单的测试应用程序来测试它。
这是代码:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
@Configuration
public class ServiceConfiguration {
@Bean
public RestTemplate restTemplate(){
return new RestTemplate();
}
}
@RestController
public class ServiceController {
@Autowired
private AlbumService albumService;
@GetMapping("/albums")
ResponseEntity<String> getAlbums() {
return albumService.getAlbums();
}
}
@Slf4j
@Service
public class AlbumService {
@Autowired
private RestTemplate restTemplate;
@CircuitBreaker(name = "albumService", fallbackMethod = "getDefaultAlbumList")
public ResponseEntity<String> getAlbums() {
String url = MockNeat.secure().probabilites(String.class)
.add(0.7, "https://wrong-url.com")
.add(0.3, "https://jsonplaceholder.typicode.com/albums").val();
return new ResponseEntity<>(restTemplate.getForObject(url, String.class), HttpStatus.OK);
}
private ResponseEntity<String> getDefaultAlbumList(Exception ex) throws URISyntaxException, IOException {
log.info("Recovered: " + ex.getMessage());
return new ResponseEntity<>(new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("fallback-album-list.json").toURI()))), HttpStatus.OK);
}
}
resilience4j:
circuitbreaker:
configs:
default:
registerHealthIndicator: true
slidingWindowSize: 10
minimumNumberOfCalls: 5
permittedNumberOfCallsInHalfOpenState: 3
automaticTransitionFromOpenToHalfOpenEnabled: true
waitDurationInOpenState: 5s
failureRateThreshold: 50
eventConsumerBufferSize: 10
instances:
albumService:
baseConfig: default
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: always
metrics:
distribution:
percentiles-histogram:
http:
server:
request: true
resielence4j:
circuitbreaker:
calls: true
最佳答案
发现问题了!
我忘记将 spring-aop 作为依赖项包含在内!
这是我的 pom.xml,以防有人遇到同样的问题:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>r4j</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>r4j</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<repositories>
<repository>
<id>jcenter</id>
<url>https://jcenter.bintray.com/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.andreinc.mockneat</groupId>
<artifactId>mockneat</artifactId>
<version>0.3.9</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-spring-boot2</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>2.3.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.3.0.RELEASE</version>
</dependency>
</dependencies>
</project>
关于java - spring-boot2 上的 Resilience4j - 断路器未打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61917010/
断路器工作原理 1、 如果经过断路器的流量超过了一定的阈值,HystrixCommandProperties.circuitBreakerRequestVolumeThreshold(); 举个例
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 3 年前。 Improve this ques
我正在尝试设计一个断路器/开关,它可以在某些事件中关闭和打开。我使用 SVG 设计了断路器,并使用 css 动画和转换属性来为它的关闭设置动画。 使用 transform-origin: bottom
在 Hadoop YARN 集群中使用 Apache Spark 1.6.2。 一些(简单的)查询会消耗大量资源,我看到我们的开发人员针对 1To 文件运行 SELECT * FROM DB!因此,它
我知道没有办法杀死 iframe 断路器......但是,我想知道,有没有办法优雅地处理它。 到目前为止,我在退出之前设法检测到它,使用 .我想知道是否可以阻止它加载iframe或强制它在新窗口中打
我观察到 Hystrix 将所有来自命令的异常视为断路目的的失败。它包括从 command run() 方法抛出并由 Hystrix 本身创建的异常,例如HystrixTimeoutException
断路器(curcuit breaker)模式 在分布式环境下,特别是微服务结构的分布式系统中, 一个软件系统调用另外一个远程系统是非常普遍的。这种远程调用的被调用方可能是另外一个进程,或者是跨网路
有没有办法配置 Micronaut 断路器,使其不针对特定的 HTTP 状态代码打开?例如,如果我查找某个项目但未找到该项目,则服务器可能会返回 HTTP 状态 404。这可能是一个完全有效的响应,我
问题: 自从从 ES-5.4 升级到 ES-7.2 后,当我尝试从我的多线程 Java 应用程序(使用 elasticsearch-rest-high-level-client-7.2.0.jar j
在官方 https://spring.io/guides/gs/circuit-breaker/手册有 业务方法(阅读列表) 回退方法(可靠) @HystrixCommand(fallbackMeth
我想通过重试和 Hystrix 断路器实现 Apache Camel 路由。我的路线如下所示: ...... java.lang.Exception
想问一个关于两种技术的问题。 我们首先从一个必须调用其他第三方 rest API 的应用程序开始,因此,我们在 SpringBoot Webflux 项目中使用了 Webflux WebClient。
我是一名优秀的程序员,十分优秀!