use of io.github.resilience4j.bulkhead.event.BulkheadEvent in project resilience4j by resilience4j.
the class BulkheadChain method execute.
@Override
public void execute(Chain chain) throws Exception {
String prefix = chain.getRegistry().get(Resilience4jConfig.class).getEndpoints().getBulkheads().getPath();
chain.prefix(prefix, chain1 -> {
chain1.get("events", ctx -> Promise.<BulkheadEventsEndpointResponse>async(d -> {
BulkheadEventsEndpointResponse response = new BulkheadEventsEndpointResponse(eventConsumerRegistry.getAllEventConsumer().flatMap(CircularEventConsumer::getBufferedEvents).sorted(Comparator.comparing(BulkheadEvent::getCreationTime)).map(BulkheadEventDTO::createEventDTO).toJavaList());
d.success(response);
}).then(r -> ctx.render(Jackson.json(r))));
chain1.get("stream/events", ctx -> {
Seq<Flowable<BulkheadEvent>> eventStreams = bulkheadRegistry.getAllBulkheads().map(bulkhead -> RxJava2Adapter.toFlowable(bulkhead.getEventPublisher()));
Function<BulkheadEvent, String> data = b -> Jackson.getObjectWriter(chain1.getRegistry()).writeValueAsString(BulkheadEventDTO.createEventDTO(b));
ServerSentEvents events = ServerSentEvents.serverSentEvents(Flowable.merge(eventStreams), e -> e.id(BulkheadEvent::getBulkheadName).event(c -> c.getEventType().name()).data(data));
ctx.render(events);
});
chain1.get("events/:name", ctx -> {
String bulkheadName = ctx.getPathTokens().get("name");
Promise.<BulkheadEventsEndpointResponse>async(d -> {
BulkheadEventsEndpointResponse response = new BulkheadEventsEndpointResponse(eventConsumerRegistry.getEventConsumer(bulkheadName).getBufferedEvents().map(BulkheadEventDTO::createEventDTO).toJavaList());
d.success(response);
}).then(r -> ctx.render(Jackson.json(r)));
});
chain1.get("stream/events/:name", ctx -> {
String bulkheadName = ctx.getPathTokens().get("name");
Bulkhead bulkhead = bulkheadRegistry.getAllBulkheads().find(b -> b.getName().equals(bulkheadName)).getOrElseThrow(() -> new IllegalArgumentException(String.format("bulkhead with name %s not found", bulkheadName)));
Function<BulkheadEvent, String> data = b -> Jackson.getObjectWriter(chain1.getRegistry()).writeValueAsString(BulkheadEventDTO.createEventDTO(b));
ServerSentEvents events = ServerSentEvents.serverSentEvents(RxJava2Adapter.toFlowable(bulkhead.getEventPublisher()), e -> e.id(BulkheadEvent::getBulkheadName).event(c -> c.getEventType().name()).data(data));
ctx.render(events);
});
chain1.get("events/:name/:type", ctx -> {
String bulkheadName = ctx.getPathTokens().get("name");
String eventType = ctx.getPathTokens().get("type");
Promise.<BulkheadEventsEndpointResponse>async(d -> {
BulkheadEventsEndpointResponse response = new BulkheadEventsEndpointResponse(eventConsumerRegistry.getEventConsumer(bulkheadName).getBufferedEvents().filter(event -> event.getEventType() == BulkheadEvent.Type.valueOf(eventType.toUpperCase())).map(BulkheadEventDTO::createEventDTO).toJavaList());
d.success(response);
}).then(r -> ctx.render(Jackson.json(r)));
});
chain1.get("stream/events/:name/:type", ctx -> {
String bulkheadName = ctx.getPathTokens().get("name");
String eventType = ctx.getPathTokens().get("type");
Bulkhead bulkhead = bulkheadRegistry.getAllBulkheads().find(b -> b.getName().equals(bulkheadName)).getOrElseThrow(() -> new IllegalArgumentException(String.format("bulkhead with name %s not found", bulkheadName)));
Flowable<BulkheadEvent> eventStream = RxJava2Adapter.toFlowable(bulkhead.getEventPublisher()).filter(event -> event.getEventType() == BulkheadEvent.Type.valueOf(eventType.toUpperCase()));
Function<BulkheadEvent, String> data = b -> Jackson.getObjectWriter(chain1.getRegistry()).writeValueAsString(BulkheadEventDTO.createEventDTO(b));
ServerSentEvents events = ServerSentEvents.serverSentEvents(eventStream, e -> e.id(BulkheadEvent::getBulkheadName).event(c -> c.getEventType().name()).data(data));
ctx.render(events);
});
});
}
use of io.github.resilience4j.bulkhead.event.BulkheadEvent in project resilience4j by resilience4j.
the class SemaphoreBulkheadTest method setUp.
@Before
public void setUp() {
BulkheadConfig config = BulkheadConfig.custom().maxConcurrentCalls(2).maxWaitTime(0).build();
bulkhead = Bulkhead.of("test", config);
testSubscriber = RxJava2Adapter.toFlowable(bulkhead.getEventPublisher()).map(BulkheadEvent::getEventType).test();
}
Aggregations