我在响应式 API 弹簧启动应用程序中使用弹性 4j 进行容错。我可以看到所有事件都被视为成功,即使 Mono 返回错误。
服务层
@Override
@CircuitBreaker(name = "member-service")
public Mono<String> getMemberInfo(String memberId) {
return wsClient.getMemberInfo(memberId);
// This call will return WSException whenever there is 4XX or 5XX error
}
application.yml配置
resilience4j.circuitbreaker:
backends:
member-service:
ringBufferSizeInClosedState: 1
ringBufferSizeInHalfOpenState: 2
waitInterval: 10000
failureRateThreshold: 75
registerHealthIndicator: true
recordExceptions:
- com.xx.WSException
ignoreExceptions:
- com.xxx.WSClientException
我故意更改了 URI 路径,以便 WebClient 总是返回 404 错误,这会引发 WSException。当我看到下面的端点时,类型总是成功的。我错过了什么?
http://localhost:8088/circuitbreaker-events/member-service
{
"circuitBreakerEvents": [
{
"circuitBreakerName": "member-service",
"type": "SUCCESS",
"creationTime": "2019-02-18T21:56:21.588+05:30[Asia/Calcutta]",
"durationInMs": 6
},
{
"circuitBreakerName": "member-service",
"type": "SUCCESS",
"creationTime": "2019-02-18T21:56:21.588+05:30[Asia/Calcutta]",
"durationInMs": 5
},
{
"circuitBreakerName": "member-service",
"type": "SUCCESS",
"creationTime": "2019-02-18T21:56:21.588+05:30[Asia/Calcutta]",
"durationInMs": 6
}
}