`

Vert.x开发指南

 
阅读更多

转自:http://www.cnblogs.com/huligong1234/p/4983869.html

Vert.x入门体验

一、概述

Vert.x(http://vertx.io)是一个基于JVM、轻量级、高性能的应用平台,非常适用于最新的移动端后台、互联网、企业应用架构.

二、安装配置

  • 访问Vert.x官网 http://vertx.io下载Vert.x包vert.x-3.1.0-full.zip
  • 配置环境变量
    创建环境变量VERTX_HOME=C:\vertx
    将%VERTX_HOME%\bin 追加到path变量上。
    通过vertx -version命令查看版本号

三、 示例

3.1 Vertx-Java命令行运行

//EchoServer.java
import io.vertx.core.AbstractVerticle;
public class EchoServer extends AbstractVerticle {
    publicvoidstart() {
        vertx.createHttpServer().requestHandler(req -> {
            req.response()
            .putHeader("content-type", "text/plain")
            .end("Hello from Vert.x!");
        }).listen(8080);
    }
}
vertx run EchoServer.java 
curl http://localhost:8080/

3.2 Vertx-Java main方法方式运行

//pom.xml
...
<dependencies>
    <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-core</artifactId>
        <version>3.1.0</version>
    </dependency>
</dependencies> 
...
//App.java
import io.vertx.core.Vertx;
public class App {
    publicstaticvoidmain(String[] args) {
        Vertx.vertx().createHttpServer().requestHandler(req -> req.response().
        end("Hello World!")).listen(8080);
    }
} 
In IDE, Run AS Java Application
curl http://localhost:8080/

3.3 Vertx-JavaScript命令行运行

//echo_server.js
vertx.createHttpServer().requestHandler(function (req) {
    req.response().putHeader("content-type", "text/html").end("<html><body><h1>
    Hello fromvert.x!</h1></body></html>");
}).listen(8080); 
vertx run echo_server.js
curl http://localhost:8080/

四、更多参考

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics