Created
February 24, 2020 20:59
-
-
Save brachi-wernick/730a186fee2ef40cacfad0cd048429c2 to your computer and use it in GitHub Desktop.
Vertx hello world
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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