Вот мое приложение Hello World, использующее IntelliJ Idea, vert.x -
Vertical:
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.ext.web.Router;
import static com.sun.xml.internal.ws.spi.db.BindingContextFactory.LOGGER;
public class MyVerticle extends AbstractVerticle {
@Override
public void start(Future<Void> startFuture) throws Exception {
Router router = Router.router(vertx);
router.route("/").handler(routingContext -> {
HttpServerResponse response = routingContext.response();
response.putHeader("content-type", "text/html")
.end("<h1> Hello Vert.x </h>");
});
vertx.createHttpServer().requestHandler(router::accept)
.listen(8070, http -> {
if (http.succeeded()) {
LOGGER.info("Started Server at port 8070");
} else {
startFuture.fail(http.cause());
}
});
vertx.createHttpServer().requestHandler(req -> {
req.response()
.putHeader("content-type", "text/plain")
.end("Hello from Vert.x!");
}).listen(8888, http -> {
if (http.succeeded()) {
startFuture.complete();
System.out.println("HTTP server started on port 8888");
} else {
startFuture.fail(http.cause());
}
});
router.route("/test").handler(routingContext -> {
HttpServerResponse response = routingContext.response();
response.putHeader("content-type","text/html")
.end("<h2> This is another end point with same port </h2>");
});
vertx.createHttpServer().requestHandler(router::accept).listen(8070,http ->{
if(http.succeeded()){
LOGGER.info("Another server started 8070");
}else{
startFuture.fail(http.cause());
}
});
}
@Override
public void stop() {
LOGGER.info("Shutting down application");
}
}
Основной метод для развертывания Verticle
import com.testproject.starter.verticles.MyVerticle;
import io.vertx.core.Vertx;
public class MyVerticleTest {
public static void main(String[] args) {
Vertx vertex = Vertx.vertx();
MyVerticle myVerticle = new MyVerticle();
vertex.deployVerticle(myVerticle);
}
}
Теперь вы можете следовать нижеуказанным URL -1. http://localhost:88882. http://localhost:8070/testДля запуска приложения не требуется tomcat.
Ссылка: https://vertx.io/docs/
Полезные ссылки - https://github.com/vert-x3/vertx-awesome