use of com.bob.vertx.webapi.service.DatabaseService in project vertx-swagger by bobxwang.
the class IndexVerticle method start.
@Override
public void start(Future<Void> startFuture) throws Exception {
logger.info("in has param start");
router.get("/index").handler(ctx -> {
ctx.response().putHeader("content-type", "application/json;charset=UTF-8");
ctx.response().end(new JsonObject().put("index", "index").put("now", new Date().toString()).encodePrettily());
});
router.get("/").handler(ctx -> {
// DeliveryOptions options = new DeliveryOptions().addHeader("action", "all-apges");
// vertx.eventBus().send(wikiDbQueue, new JsonObject(), options, reply -> {
// if (reply.succeeded()) {
// JsonObject body = (JsonObject) reply.result().body();
// ctx.response().putHeader("content-type", "application/json;charset=UTF-8");
// ctx.response().end(new JsonObject()
// .put("index", "index")
// .put("dbthread", body.getValue("dbthread"))
// .put("thread", Thread.currentThread().getName())
// .put("pages", body.getString("pages")).encodePrettily());
// } else {
// ctx.fail(reply.cause());
// }
// });
DatabaseService databaseService = DatabaseService.createProxy(vertx, wikiDbQueue);
databaseService.fetchAllPages(ar -> {
if (ar.succeeded()) {
JsonObject jsonObject = ar.result();
ctx.response().putHeader("content-type", "application/json;charset=UTF-8");
ctx.response().end(new JsonObject().put("index", "index").put("dbthread", jsonObject.getValue("dbthread")).put("thread", Thread.currentThread().getName()).put("pages", jsonObject.getString("pages")).encodePrettily());
} else {
ctx.fail(ar.cause());
}
});
});
Future<String> dbVerticle = Future.future();
vertx.deployVerticle(new WorkVerticle(), dbVerticle.completer());
dbVerticle.setHandler(ar -> {
if (ar.succeeded()) {
startFuture.complete();
} else {
startFuture.fail(ar.cause());
}
});
}
use of com.bob.vertx.webapi.service.DatabaseService in project vertx-swagger by bobxwang.
the class WorkVerticle method start.
@Override
public void start() throws Exception {
super.start();
// vertx.eventBus().consumer(wikiDbQueue, this::onMessage);
serviceBinder = new ServiceBinder(vertx);
DatabaseService service = DatabaseService.create(vertx);
if (consumer == null) {
consumer = serviceBinder.setAddress(wikiDbQueue).register(DatabaseService.class, service);
}
}
Aggregations