List of usage examples for io.vertx.core.eventbus Message reply
default void reply(@Nullable Object message)
From source file:HelloServiceVerticle.java
License:Apache License
@Override public void handle(Message<JsonObject> requestMsg) { System.out.println("Hello-Service-Verticle received request : " + requestMsg.body().encodePrettily()); JsonObject replyMsg = new JsonObject(); replyMsg.put("body", "HELLO " + requestMsg.body().getString("body").toUpperCase()); requestMsg.reply(replyMsg); System.out.println("Hello-Service-Verticle sent reply : " + replyMsg.encodePrettily()); }
From source file:ServerVerticle.java
License:Apache License
@Override public void handle(Message<JsonObject> requestMsg) { System.out.println("Server verticle received request : " + requestMsg.body().encodePrettily()); JsonObject replyMsg = new JsonObject(); replyMsg.put("body", "HELLO " + requestMsg.body().getString("body").toUpperCase()); requestMsg.reply(replyMsg); System.out.println("Server verticle sent reply : " + replyMsg.encodePrettily()); }
From source file:cm.study.vertx.database.WikiDatabaseServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {/*from w ww. ja v a 2 s . c o m*/ JsonObject json = msg.body(); String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); } accessed(); switch (action) { case "fetchAllPages": { service.fetchAllPages(createHandler(msg)); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.reply(new ServiceException(500, t.getMessage())); throw t; } }
From source file:cm.study.vertx.database.WikiDatabaseServiceVertxProxyHandler.java
License:Apache License
private <T> Handler<AsyncResult<T>> createHandler(Message msg) { return res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); }// w ww.j a va2s. c o m } else { if (res.result() != null && res.result().getClass().isEnum()) { msg.reply(((Enum) res.result()).name()); } else { msg.reply(res.result()); } } }; }
From source file:cm.study.vertx.database.WikiDatabaseServiceVertxProxyHandler.java
License:Apache License
private <T> Handler<AsyncResult<List<T>>> createListHandler(Message msg) { return res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); }//from w ww . java 2s . co m } else { msg.reply(new JsonArray(res.result())); } }; }
From source file:cm.study.vertx.database.WikiDatabaseServiceVertxProxyHandler.java
License:Apache License
private <T> Handler<AsyncResult<Set<T>>> createSetHandler(Message msg) { return res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); }//from w w w. j av a 2 s . co m } else { msg.reply(new JsonArray(new ArrayList<>(res.result()))); } }; }
From source file:cm.study.vertx.database.WikiDatabaseServiceVertxProxyHandler.java
License:Apache License
private Handler<AsyncResult<List<Character>>> createListCharHandler(Message msg) { return res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); }//from ww w. ja v a 2s .co m } else { JsonArray arr = new JsonArray(); for (Character chr : res.result()) { arr.add((int) chr); } msg.reply(arr); } }; }
From source file:cm.study.vertx.database.WikiDatabaseServiceVertxProxyHandler.java
License:Apache License
private Handler<AsyncResult<Set<Character>>> createSetCharHandler(Message msg) { return res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); }/*w w w. j a va2 s . com*/ } else { JsonArray arr = new JsonArray(); for (Character chr : res.result()) { arr.add((int) chr); } msg.reply(arr); } }; }
From source file:com.appdocker.iop.InternetOfPeopleServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {//from w w w . ja va 2 s . co m JsonObject json = msg.body(); String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); } accessed(); switch (action) { case "hello": { service.hello((java.lang.String) json.getValue("message"), createHandler(msg)); break; } case "close": { service.close(); close(); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.reply(new ServiceException(500, t.getMessage())); throw t; } }
From source file:com.cyngn.vertx.bosun.BosunReporter.java
License:Apache License
/** * Handles posting to the index endpoint * * @param message the message to send//from www . j a v a 2 s. co m */ private void doIndex(Message<JsonObject> message) { OpenTsDbMetric metric = getMetricFromMessage(message); if (metric == null) { return; } // ignore it we've seen it lately String key = metric.getDistinctKey(); if (distinctMetrics.getIfPresent(key) != null) { message.reply(new JsonObject().put(RESULT_FIELD, BosunResponse.EXISTS_MSG)); return; } // cache it distinctMetrics.put(key, true); metricsIndexed.incrementAndGet(); sendData(INDEX_API, metric.asJson().encode(), message); }