Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run embedded vert.x?

Tags:

java

main

vert.x

I've wrote a Groovy MainApp with main(args).

When I launch it, the JVM exit directly ("End of JVM execution !").

import org.vertx.groovy.core.Vertx

class MainApp {

    public static void main(String[] args) {

        Vertx vertx = VertxFactory.newVertx();

        vertx.createHttpServer().requestHandler{ request -> 
            println "A request has arrived on the server!" 
        }.listen(8080)

        println "End of JVM execution !"
    }
}

How to run correctly an embedded HTTP server with vert.x?

like image 637
ronan michaux Avatar asked Dec 18 '12 15:12

ronan michaux


1 Answers

I had the same problem with Java. I ended up putting an object in .wait() after all the vert.x code. Looks horrible, but actually makes sense because it gives me a trigger to shutdown the server on demand (via .notify()).

This is non trivial, should be mentioned on the Vert.x official documentation.

like image 101
sscarduzio Avatar answered Nov 07 '22 14:11

sscarduzio