Vert.x入門體驗


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 {
    public void start() {
        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 {
    public static void main(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 from vert.x!</h1></body></html>");
}).listen(8080); 
vertx run echo_server.js
curl http://localhost:8080/

四、更多參考


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM