Skip to content

Instantly share code, notes, and snippets.

@brachi-wernick
Created February 24, 2020 20:59
Show Gist options
  • Save brachi-wernick/730a186fee2ef40cacfad0cd048429c2 to your computer and use it in GitHub Desktop.
Save brachi-wernick/730a186fee2ef40cacfad0cd048429c2 to your computer and use it in GitHub Desktop.
Vertx hello world
public class MainVerticle extends AbstractVerticle
{
@Override
public void start(Promise<Void> startPromise) throws Exception {
Router router = Router.router(vertx);
router.get("/hello").handler(this::hello);
vertx.createHttpServer().requestHandler(router).listen(8882, http -> {
if (http.succeeded()) {
startPromise.complete();
System.out.println("HTTP server started on port 8882");
} else {
startPromise.fail(http.cause());
}
});
}
private void hello(RoutingContext routingContext) {
routingContext.response()
.putHeader("content-type", "text/plain")
.end("Hello from Vert.x!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment