Spring / Resilience4j Interview questions
How does Resilience4j integrate with reactive streams in WebFlux?
The resilience4j-reactor module supplies operators - CircuitBreakerOperator, RetryOperator, RateLimiterOperator, BulkheadOperator, TimeLimiterOperator - that plug into a Mono or Flux pipeline via .transformDeferred(...), rather than wrapping a blocking Supplier the way the core modules do.
Mono<Response> result = webClient.get() .uri("/data") .retrieve() .bodyToMono(Response.class) .transformDeferred(CircuitBreakerOperator.of(circuitBreaker)) .transformDeferred(RetryOperator.of(retry));
transformDeferred specifically (rather than transform) matters here because it re-applies the operator on every new subscription, which is required for Retry to actually re-subscribe to the upstream on each attempt instead of replaying a single cached subscription.
Resilience4j Spring Boot's annotations also work directly on methods returning Mono/Flux without manual operator wiring, since the framework detects the reactive return type and applies the equivalent reactive decorator automatically under the hood.
More Related questions...