zoukankan      html  css  js  c++  java
  • 第一个Vert.x程序

    Jar依赖

    <dependency>
                <groupId>io.vertx</groupId>
                <artifactId>vertx-core</artifactId>
                <version>3.3.3</version>
            </dependency>
            <dependency>
                <groupId>io.vertx</groupId>
                <artifactId>vertx-web</artifactId>
                <version>3.0.0</version>
            </dependency>

    HelloWorld

    public class HelloWorld  extends AbstractVerticle{
    
        @Override
        public void start() throws Exception {
            super.start();
            final Router router = Router.router(vertx);
    
            router.route().handler(BodyHandler.create());
            //访问路由
            router.get("/hello").handler(new Handler<RoutingContext>() {
                @Override
                public void handle(RoutingContext event) {
                    event.response().putHeader("content-type","text/html").end("hello world");
                }
            });
            //创建服务端监听
            vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {
                @Override
                public void handle(HttpServerRequest httpServerRequest) {
                    router.accept(httpServerRequest);
                }
            }).listen(8080);
        }
    
        public static void main(String[] args) {
            String verticleId=HelloWorld.class.getName();
            VertxOptions options =new VertxOptions();
            Consumer<Vertx> runner = vertx1 -> {
                vertx1.deployVerticle(verticleId);
            };
            Vertx vertx = Vertx.vertx(options);
            runner.accept(vertx);
        }
    
    }
    

     浏览器访问:http://127.0.0.1:8080/hello 返回hello world

    参考:http://blog.csdn.net/caihuangshi/article/details/51648182

    官方demo:https://github.com/vert-x3/vertx-examples/tree/master/web-examples/src/main/java/io/vertx/example/web

  • 相关阅读:
    每日日报
    设计模式分类及典型实现
    SpringBean的生命周期
    Nginx
    大话--单例模式
    类图--小总结
    设计模式原则概述
    大话--装饰者模式
    Redis基础
    SpringIOC的实现原理
  • 原文地址:https://www.cnblogs.com/yissheng/p/7513484.html
Copyright © 2011-2022 走看看