Created
December 29, 2017 16:34
-
-
Save bsandhu/2342d17f057e526c78ac48ec1997af2d to your computer and use it in GitHub Desktop.
Vert.x verticle with executeBlocking
This file contains 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() throws Exception { | |
ObjectMapper objectMapper = new ObjectMapper(); | |
vertx.createHttpServer().requestHandler(req -> { | |
vertx.executeBlocking(future -> { | |
try { | |
Thread.sleep(100); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
future.complete(new User("First", "Last", "122-100-1221")); | |
}, | |
false, | |
res -> { | |
try { | |
req.response() | |
.setStatusCode(200) | |
.putHeader("content-type", "text/html") | |
.end("<!DOCTYPE html><html><body>" + | |
"<h1>Vert.x worker " + Thread.currentThread().getName() + "</h1>" + | |
"<hr/>" + | |
"<h2>" + objectMapper.writeValueAsString(res.result()) + "</h2>" + | |
"</body></html>"); | |
} catch (JsonProcessingException e) { | |
e.printStackTrace(); | |
req.response() | |
.setStatusCode(500) | |
.end(); | |
} | |
}); | |
}).listen(8080); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment