Handling requests and calling the next handler
当Vert.x-Web``route一个HTTP Request到一个与之匹配的route,它会向该route的handler传递一个RoutingContext实例.
如果在当前handler里,你不想结束response, 那么你应该调用下一个相匹配的route继续处理该请求.
你没有必要在当前handler执行完之前调用下一个route, 你可以稍后再做这件事.
Route route1 = router.route("/some/path/").handler(routingContext -> {HttpServerResponse response = routingContext.response();// enable chunked responses because we will be adding data as// we execute over other handlers. This is only required once and// only if several handlers do output.response.setChunked(true);response.write("route1\n");// Call the next matching route after a 5 second delayroutingContext.vertx().setTimer(5000, tid -> routingContext.next());});Route route2 = router.route("/some/path/").handler(routingContext -> {HttpServerResponse response = routingContext.response();response.write("route2\n");// Call the next matching route after a 5 second delayroutingContext.vertx().setTimer(5000, tid -> routingContext.next());});Route route3 = router.route("/some/path/").handler(routingContext -> {HttpServerResponse response = routingContext.response();response.write("route3");// Now end the responseroutingContext.response().end();});
在上面的例子中, route1被写到response的5秒钟之后,route2被写到response,在过了5秒钟之后,route3被写到response,然后结束掉response.
注意这一切的发生都是非阻塞的,
