Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import io.vertx.core.AsyncResult
import io.vertx.core.Future
import io.vertx.core.json.JsonObject
import io.vertx.core.logging.LoggerFactory
import io.vertx.groovy.core.eventbus.Message
import io.vertx.groovy.ext.web.RoutingContext
import io.vertx.lang.groovy.GroovyVerticle
import static groovy.json.JsonOutput.toJson
class Solution1 extends GroovyVerticle {
void start() {
Future allDone = Future.future()
Future eventVerticleFuture = Future.future()
vertx.deployVerticle('groovy:EventVerticle.groovy', eventVerticleFuture.completer())
eventVerticleFuture.compose({ v ->
Future anotherVerticleFuture = Future.future()
vertx.deployVerticle('groovy:AnotherVerticle.groovy', anotherVerticleFuture.completer())
}, allDone)
void rootHandler(RoutingContext ctx) {
def msg = new JsonObject([path: ctx.request().path()])
def replyHandler = { AsyncResult<Message> reply -> this.replyHandler(ctx, reply) }
vertx.eventBus().send('event.verticle', msg, replyHandler)
void replyHandler(RoutingContext ctx, AsyncResult<Message> reply) {
def response = ctx.response()
.putHeader('Content-Type', 'application/json')
if (reply.succeeded()) {
.end(new JsonObject(reply.result().body()).encodePrettily())
} else {
.setStatusMessage('Server Error')
void deployHandler(Future f) {
if (f.succeeded()) {
LoggerFactory.getLogger(Solution1).info('Successfully deployed all verticles')
// If the EventVerticle successfully deployed, configure and start the HTTP server
def router = Router.router(vertx)
vertx.createHttpServer() // Create a new HttpServer
.requestHandler(router.&accept) // Register a request handler
.listen(8080, '') // Listen on
} else {
LoggerFactory.getLogger(Solution1).error('Failed to deploy verticle', f.cause())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.