use of reactor.core.publisher.WorkQueueProcessor in project reactor-netty by reactor.
the class TcpServerTests method test5.
@Test
@Ignore
public void test5() throws Exception {
// Hot stream of data, could be injected from anywhere
EmitterProcessor<String> broadcaster = EmitterProcessor.create();
// Get a reference to the tail of the operation pipeline (microbatching + partitioning)
final Processor<List<String>, List<String>> processor = WorkQueueProcessor.<List<String>>builder().autoCancel(false).build();
broadcaster.bufferTimeout(10, Duration.ofSeconds(1)).log("broadcaster").subscribe(processor);
// on a server dispatching data on the default shared dispatcher, and serializing/deserializing as string
// Listen for anything exactly hitting the root URI and route the incoming connection request to the callback
NettyContext s = HttpServer.create(0).newRouter(r -> r.get("/", (request, response) -> {
// prepare a response header to be appended first before any reply
response.addHeader("X-CUSTOM", "12345");
// returning a stream of String from each microbatch merged
return response.sendString(Flux.from(processor).flatMap(Flux::fromIterable).take(Duration.ofSeconds(5)).concatWith(Flux.just("end\n")));
})).block(Duration.ofSeconds(30));
for (int i = 0; i < 50; i++) {
Thread.sleep(500);
broadcaster.onNext(System.currentTimeMillis() + "\n");
}
s.dispose();
}
Aggregations