use of io.github.resilience4j.retry.event.RetryEvent in project resilience4j by resilience4j.
the class RetryChain method execute.
@Override
public void execute(Chain chain) throws Exception {
String prefix = chain.getRegistry().get(Resilience4jConfig.class).getEndpoints().getRetries().getPath();
chain.prefix(prefix, chain1 -> {
chain1.get("events", ctx -> Promise.<RetryEventsEndpointResponse>async(d -> {
List<RetryEventDTO> eventsList = eventConsumerRegistry.getAllEventConsumer().flatMap(CircularEventConsumer::getBufferedEvents).sorted(Comparator.comparing(RetryEvent::getCreationTime)).map(RetryEventDTO::createRetryEventDTO).toJavaList();
d.success(new RetryEventsEndpointResponse(eventsList));
}).then(r -> ctx.render(Jackson.json(r))));
chain1.get("stream/events", ctx -> {
Seq<Flowable<RetryEvent>> eventStreams = retryRegistry.getAllRetries().map(retry -> toFlowable(retry.getEventPublisher()));
Function<RetryEvent, String> data = r -> Jackson.getObjectWriter(chain1.getRegistry()).writeValueAsString(RetryEventDTO.createRetryEventDTO(r));
ServerSentEvents events = ServerSentEvents.serverSentEvents(Flowable.merge(eventStreams), e -> e.id(RetryEvent::getName).event(c -> c.getEventType().name()).data(data));
ctx.render(events);
});
chain1.get("events/:name", ctx -> {
String retryName = ctx.getPathTokens().get("name");
Promise.<RetryEventsEndpointResponse>async(d -> {
List<RetryEventDTO> eventsList = eventConsumerRegistry.getEventConsumer(retryName).getBufferedEvents().sorted(Comparator.comparing(RetryEvent::getCreationTime)).map(RetryEventDTO::createRetryEventDTO).toJavaList();
d.success(new RetryEventsEndpointResponse(eventsList));
}).then(r -> ctx.render(Jackson.json(r)));
});
chain1.get("stream/events/:name", ctx -> {
String rateLimiterName = ctx.getPathTokens().get("name");
Retry retry = retryRegistry.getAllRetries().find(rL -> rL.getName().equals(rateLimiterName)).getOrElseThrow(() -> new IllegalArgumentException(String.format("rate limiter with name %s not found", rateLimiterName)));
Function<RetryEvent, String> data = r -> Jackson.getObjectWriter(chain1.getRegistry()).writeValueAsString(RetryEventDTO.createRetryEventDTO(r));
ServerSentEvents events = ServerSentEvents.serverSentEvents(toFlowable(retry.getEventPublisher()), e -> e.id(RetryEvent::getName).event(c -> c.getEventType().name()).data(data));
ctx.render(events);
});
chain1.get("events/:name/:type", ctx -> {
String retryName = ctx.getPathTokens().get("name");
String eventType = ctx.getPathTokens().get("type");
Promise.<RetryEventsEndpointResponse>async(d -> {
List<RetryEventDTO> eventsList = eventConsumerRegistry.getEventConsumer(retryName).getBufferedEvents().sorted(Comparator.comparing(RetryEvent::getCreationTime)).filter(event -> event.getEventType() == RetryEvent.Type.valueOf(eventType.toUpperCase())).map(RetryEventDTO::createRetryEventDTO).toJavaList();
d.success(new RetryEventsEndpointResponse(eventsList));
}).then(r -> ctx.render(Jackson.json(r)));
});
chain1.get("stream/events/:name/:type", ctx -> {
String retryName = ctx.getPathTokens().get("name");
String eventType = ctx.getPathTokens().get("type");
Retry retry = retryRegistry.getAllRetries().find(rL -> rL.getName().equals(retryName)).getOrElseThrow(() -> new IllegalArgumentException(String.format("rate limiter with name %s not found", retryName)));
Flowable<RetryEvent> eventStream = toFlowable(retry.getEventPublisher()).filter(event -> event.getEventType() == RetryEvent.Type.valueOf(eventType.toUpperCase()));
Function<RetryEvent, String> data = r -> Jackson.getObjectWriter(chain1.getRegistry()).writeValueAsString(RetryEventDTO.createRetryEventDTO(r));
ServerSentEvents events = ServerSentEvents.serverSentEvents(eventStream, e -> e.id(RetryEvent::getName).event(c -> c.getEventType().name()).data(data));
ctx.render(events);
});
});
}
Aggregations