资料内容:
响应式编程是⼀种⾮阻塞异步编程
import reactor.ipc.netty.tcp.TcpServer;
import reactor.ipc.netty.tcp.TcpClient;
CountDownLatch latch = new CountDownLatch(10);
TcpServer server = TcpServer.create(port);
TcpClient client = TcpClient.create("localhost", port);
final JsonCodec<Pojo, Pojo> codec = new JsonCodec<Pojo, Pojo>(Pojo.class);
server.start(input -> input.send(input.decode(codec).log("serve").map(codec), 5)).await();
client.start(input -> {
input.take(10).decode(codec).log("receive").subscribe(data -> latch.countDown());
input.send(Flux.range(1, 10).map( it -> new Pojo("test" + it)).log(“send").map(codec))
.subscribe();
return Mono.never();
}).await();
latch.await(10, TimeUnit.SECONDS);
client.shutdown().await();
server.shutdown().await();