在 Vertx 中实现扇出
Implementing Fanout in Vertx
我正在实施一个 http 服务器,它使用 vertx 版本 3.5.4 将工作分散到 http 客户端。
服务器接收工作并以异步方式将其扇出给一堆客户端。但是,我需要阻塞请求线程,直到所有结果都到达。
在一个纯粹的java世界里,我会做这样的事情:
CountdownLatch latch = new CountdownLatch( 3 );
executor.submit( new Request(client1) );
executor.submit( new Request(client2) );
executor.submit( new Request(client3) );
latch.await(); // block the request thread
//In callback thread from clients
latch.countdown();
但是,在 vertx 中,我无法阻塞主事件循环线程。
阻塞初始请求线程的推荐方法是什么?
谢谢
你是对的,你不能阻塞事件循环。在异步世界,你需要组合不同的结果,最终回复请求。
查看文档的 Concurrent composition 部分。
我正在实施一个 http 服务器,它使用 vertx 版本 3.5.4 将工作分散到 http 客户端。
服务器接收工作并以异步方式将其扇出给一堆客户端。但是,我需要阻塞请求线程,直到所有结果都到达。
在一个纯粹的java世界里,我会做这样的事情:
CountdownLatch latch = new CountdownLatch( 3 );
executor.submit( new Request(client1) );
executor.submit( new Request(client2) );
executor.submit( new Request(client3) );
latch.await(); // block the request thread
//In callback thread from clients
latch.countdown();
但是,在 vertx 中,我无法阻塞主事件循环线程。 阻塞初始请求线程的推荐方法是什么?
谢谢
你是对的,你不能阻塞事件循环。在异步世界,你需要组合不同的结果,最终回复请求。
查看文档的 Concurrent composition 部分。