美文网首页
初始Vert.x

初始Vert.x

作者: 茶铺里的水 | 来源:发表于2017-10-19 14:37 被阅读10次

废话不多,先上代码:

1,添加依赖

compile group: 'io.vertx',name: 'vertx-web',version: '3.4.2'

2,上代码

package com.my;

import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.ext.web.Router;

public class VertxServer {

    public static void main(String[] args) {
        Vertx vertx = Vertx.vertx(new VertxOptions().setWorkerPoolSize(40));
        HttpServer server = vertx.createHttpServer();
        Router router = Router.router(vertx);
        router.route().handler(context -> {
            HttpServerResponse response = context.response();
            response.putHeader("content-type", "text/plain");
            response.end("Hello World from Vert.x-Web!");
        });
        server.requestHandler(router::accept).listen(9998);
    }
}

3,启动


hello world

相关文章

网友评论

      本文标题:初始Vert.x

      本文链接:https://www.haomeiwen.com/subject/rcbuuxtx.html