Search in sources :

Example 26 with CircuitBreaker

use of io.github.resilience4j.circuitbreaker.CircuitBreaker in project resilience4j by resilience4j.

the class CircuitBreakerEventsEndpoint method getEventsStreamFilteredByCircuitBreakerNameAndEventType.

@RequestMapping(value = "stream/events/{circuitBreakerName}/{eventType}", produces = MEDIA_TYPE_TEXT_EVENT_STREAM)
public SseEmitter getEventsStreamFilteredByCircuitBreakerNameAndEventType(@PathVariable("circuitBreakerName") String circuitBreakerName, @PathVariable("eventType") String eventType) {
    CircuitBreaker circuitBreaker = circuitBreakerRegistry.getAllCircuitBreakers().find(cb -> cb.getName().equals(circuitBreakerName)).getOrElseThrow(() -> new IllegalArgumentException(String.format("circuit breaker with name %s not found", circuitBreakerName)));
    Flux<CircuitBreakerEvent> eventStream = toFlux(circuitBreaker.getEventPublisher()).filter(event -> event.getEventType() == CircuitBreakerEvent.Type.valueOf(eventType.toUpperCase()));
    return CircuitBreakerEventEmitter.createSseEmitter(eventStream);
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) CircuitBreaker(io.github.resilience4j.circuitbreaker.CircuitBreaker) MediaType(org.springframework.http.MediaType) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Controller(org.springframework.stereotype.Controller) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) CircuitBreakerRegistry(io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry) ReactorAdapter.toFlux(io.github.resilience4j.adapter.ReactorAdapter.toFlux) Flux(reactor.core.publisher.Flux) CircularEventConsumer(io.github.resilience4j.consumer.CircularEventConsumer) Seq(io.vavr.collection.Seq) Comparator(java.util.Comparator) CircuitBreakerEvent(io.github.resilience4j.circuitbreaker.event.CircuitBreakerEvent) EventConsumerRegistry(io.github.resilience4j.consumer.EventConsumerRegistry) SseEmitter(org.springframework.web.servlet.mvc.method.annotation.SseEmitter) CircuitBreaker(io.github.resilience4j.circuitbreaker.CircuitBreaker) CircuitBreakerEvent(io.github.resilience4j.circuitbreaker.event.CircuitBreakerEvent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

CircuitBreaker (io.github.resilience4j.circuitbreaker.CircuitBreaker)26 Test (org.junit.Test)19 CircuitBreakerRegistry (io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry)9 CircuitBreakerConfig (io.github.resilience4j.circuitbreaker.CircuitBreakerConfig)6 CircuitBreakerEvent (io.github.resilience4j.circuitbreaker.event.CircuitBreakerEvent)6 CircuitBreakerOpenException (io.github.resilience4j.circuitbreaker.CircuitBreakerOpenException)3 InMemoryCircuitBreakerRegistry (io.github.resilience4j.circuitbreaker.internal.InMemoryCircuitBreakerRegistry)3 Type (io.github.resilience4j.circuitbreaker.event.CircuitBreakerEvent.Type)2 CircularEventConsumer (io.github.resilience4j.consumer.CircularEventConsumer)2 EventConsumerRegistry (io.github.resilience4j.consumer.EventConsumerRegistry)2 CollectorRegistry (io.prometheus.client.CollectorRegistry)2 CheckedRunnable (io.vavr.CheckedRunnable)2 Tuple (io.vavr.Tuple)2 HashMap (io.vavr.collection.HashMap)2 HashSet (io.vavr.collection.HashSet)2 Map (io.vavr.collection.Map)2 Seq (io.vavr.collection.Seq)2 Duration (java.time.Duration)2 ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2