Dar*_*ica 5 java spring-boot hystrix
我有一个 Spring Boot 应用程序,它通过 hystrix 命令迭代调用模拟服务器实例,并使用回退方法。
模拟服务器配置为始终以状态代码 500 响应。在没有circuitBreaker.sleepWindowInMilliseconds 的情况下运行时,一切正常,调用模拟服务器,然后调用回退方法。
在将circuitBreaker.sleepWindowInMilliseconds值配置为 5 分钟左右后,我希望在 5 分钟内没有调用模拟服务器,所有调用都被定向到回退方法,但事实并非如此。
看起来circuitBreaker.sleepWindowInMilliseconds配置被忽略了。
例如,如果我重新配置模拟服务以在迭代仍在运行时回复状态代码 200,它将立即打印“模拟服务响应”,而无需等待 5 分钟。
在 spring boot 主应用程序类中:
@RequestMapping("/iterate")
public void iterate() {
for (int i = 1; i<100; i++ ) {
try {
System.out.println(bookService.readingMockService());
Thread.sleep(3000);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
Run Code Online (Sandbox Code Playgroud)
在 Spring Boot 服务中:
@HystrixCommand(groupKey = "ReadingMockService", commandKey = "ReadingMockService", threadPoolKey = "ReadingMockService", fallbackMethod = "reliableMock", commandProperties = {
@HystrixProperty(name ="circuitBreaker.sleepWindowInMilliseconds", value = "300000") })
public String readingMockService() {
URI uri = URI.create("http://localhost:1080/askmock");
return this.restTemplate.getForObject(uri, String.class);
}
Run Code Online (Sandbox Code Playgroud)
模拟服务器也在同一台机器上运行,配置如下:
new MockServerClient("127.0.0.1", 1080).reset();
new MockServerClient("127.0.0.1", 1080)
.when(request("/askmock"))
.respond(response()
.withStatusCode(500)
.withBody("mockservice response")
.applyDelay());
Run Code Online (Sandbox Code Playgroud)
小智 1
来自文档: https://github.com/Netflix/Hystrix/wiki/configuration# CircuitBreaker.sleepWindowInMilliseconds
并通过查看源代码:
使用
@HystrixProperty(name="hystrix.command.ReadingMockService.circuitBreaker.sleepWindowInMilliseconds"
应该管用。
| 归档时间: |
|
| 查看次数: |
3529 次 |
| 最近记录: |