Skip to content

Instantly share code, notes, and snippets.

@downgoon
Last active May 18, 2017 05:53
Show Gist options
  • Save downgoon/49eaf2e0b569818b624052d199895893 to your computer and use it in GitHub Desktop.
Save downgoon/49eaf2e0b569818b624052d199895893 to your computer and use it in GitHub Desktop.
import io.vertx.config.ConfigRetriever;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Future;
import io.vertx.core.Verticle;
import io.vertx.core.Vertx;
public class HelloVerticle extends AbstractVerticle {
/* `http.port` can not be allowed in ` ~/.bash_profile` on Mac */
private static final String HTTP_PORT = "HTTP_PORT";
@Override
public void start(Future<Void> fut) throws Exception {
// Retrieve the port from the configuration,
// default to 8080.
// int configPort = config().getInteger(HTTP_PORT, 8080);
// System.out.println("configPort: " + configPort);
// int finalPort = retriever.getCachedConfig().getInteger(HTTP_PORT, 8080);
int finalPort = config().getInteger(HTTP_PORT, 8080);
System.out.println("finalPort: " + finalPort);
vertx.createHttpServer().requestHandler(r -> {
r.response().end("<h1>Hello World ! </h1>");
}).listen(finalPort, result -> {
if (result.succeeded()) {
fut.complete();
} else {
fut.fail(result.cause());
}
});
}
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
Verticle boxcloudVerticle = new HelloVerticle();
//
// vertx.deployVerticle(boxcloudVerticle);
// new JsonObject().put(HTTP_PORT, 10081)
DeploymentOptions options = new DeploymentOptions().setConfig(ConfigRetriever.create(vertx).getCachedConfig());
vertx.deployVerticle(boxcloudVerticle, options);
System.out.println("启动...");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment