Is there a way to configure the Micronaut Circuit Breaker so that it is not opened for specific HTTP status codes? If I for instance do a lookup on an item and that item is not found, then a server might return HTTP status 404. This might be a perfectly valid response, and I do not want the circuit breaker to open in these cases.
As far as I understand the Micronaut circuit breaker is not tied to HTTP, but there is still a solution that nearly gets me there:
@Client("${myEndpoint}")
@CircuitBreaker(attempts = "4", predicate = ServerErrorRetryPredicate.class)
public interface MyClient {
@Get
Single<MyItem> getItem(int itemId);
}
public class ServerErrorRetryPredicate implements RetryPredicate {
@Override
public boolean test(Throwable throwable) {
if (throwable instanceof HttpClientResponseException) {
HttpClientResponseException e = (HttpClientResponseException) throwable;
return e.getStatus().getCode() >= 500;
}
return true;
}
}
Here I am using the new Predicate that came with Micronaut 2, and in this case the predicate fails if the HTTP status is less than 500 (so it will fail for a HTTP status 404 that I get when the item is not found). This works perfectly well for avoiding retries, but it has no effect on circuit breakers.
Is it possible to avoid opening a circuit breaker based on the result of the predicate, like retry is skipped based on it?