Vert.x 3.0 初探(一) Hello World
2016-02-15 00:00
218 查看
摘要: Vert.x是高性能,高并发,可伸缩,支持多语言的web框架,特别适用于手机客户端的服务端
查了好多资料,示例代码都是jdk8写的,lambda表达式对于没有研究过的同学来说估计一时半会儿也没看明白,就自己写了一个通俗易懂的示例
查了好多资料,示例代码都是jdk8写的,lambda表达式对于没有研究过的同学来说估计一时半会儿也没看明白,就自己写了一个通俗易懂的示例
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>vertx.test</groupId> <artifactId>myvertx</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>myvertx</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>io.vertx</groupId> <artifactId>vertx-core</artifactId> <version>3.2.1</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>io.vertx</groupId> <artifactId>vertx-unit</artifactId> <version>3.2.1</version> <scope>test</scope> </dependency> <dependency> <groupId>io.vertx</groupId> <artifactId>vertx-web</artifactId> <version>3.2.1</version> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.3</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <manifestEntries> <Main-Class>io.vertx.core.Starter</Main-Class> <Main-Verticle>vertx.test.myvertx.VertxTest</Main-Verticle> </manifestEntries> </transformer> </transformers> <artifactSet /> <outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
package vertx.test.myvertx; import io.vertx.core.AbstractVerticle; import io.vertx.core.Handler; import io.vertx.core.http.HttpServerRequest; import io.vertx.ext.web.Router; import io.vertx.ext.web.RoutingContext; import io.vertx.ext.web.handler.BodyHandler; public class VertxTest extends AbstractVerticle { @Override public void start() throws Exception { final Router router = Router.router(vertx); router.route(); router.route().handler(BodyHandler.create()); router.get("/hello").handler(new Handler<RoutingContext>() { public void handle(RoutingContext event) { event.response().putHeader("content-type", "text/html").end("Hello World"); } }); // 传递方法引用,监听端口 vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() { public void handle(HttpServerRequest event) { router.accept(event); } }).listen(8080); } }
相关文章推荐
- 在Eclipse里调试Vert.X
- vertx初体验(1)---安装
- Vert.x,一个异步、可伸缩、并发应用框架引发的思考
- 响应式微服务 in java 译 <十四> Circuit Breakers
- 响应式微服务 in java 译 <十三> Stability and Resilience Patterns
- 响应式微服务 in java 译 <十二> service discovery
- 响应式微服务 in java 译 <十一> Are We Reactive Now?
- 响应式微服务 in java 译 Message-Based Microservices<十>
- 响应式微服务 in java 译 这就是Reactive Microservices了吗?<九>
- 响应式微服务 in java 译<八>
- 响应式微服务 in Java 译<七>
- 响应式微服务 in Java 译<六> --Let’s Start Coding!
- 响应式微服务 in Java 译<五> --Verticles—the Building Blocks
- 响应式微服务 in Java 译 --Asynchronous Development Model<四>
- 响应式微服务 in Java 译 --reactive systems<三>
- 响应式微服务 in Java 译 --理解响应式微服务和Vert.x<二>
- Vert.x Guide 总结 译<End>
- 在Event bus的消息实践上实现实时WEB特性 译<十三>
- Vert.x AngularJS编写client-side应用 译<十二>