Vertx http服务器仅创建一个实例



我正在使用vertx创建一个简单的微服务,当我启动服务器时,它只创建一个事件线程(可用时为12(。

我启动服务器的代码是

public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
int processorCounts = Runtime.getRuntime().availableProcessors();
DeploymentOptions options = new DeploymentOptions().setInstances(processorCounts);
vertx.deployVerticle( HttpRouter.class.getName(),options);
}

我的http路由器看起来像这个

@Override
public void start() throws Exception {
super.start();
Router router = Router.router(vertx);
router.get("/").handler(event -> {
event.response().end("Hello World");
});
vertx.createHttpServer().requestHandler(router::accept).listen(8001);
}

您的测试流程是什么?我假设你打开了浏览器,在同一页面上点击刷新。那么是的,相同的垂直实例将处理这些请求。原因是Vert.x在垂直实例之间平衡连接,而不是请求。

打开不同的浏览器,您应该会看到不同的事件循环名称。

相关内容

最新更新