List of usage examples for io.vertx.core.json JsonObject encodePrettily
public String encodePrettily()
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);//from ww w.j ava 2 s . c o m System.out.println("Hello-Service-Verticle sent reply : " + replyMsg.encodePrettily()); }
From source file:ClientVerticle.java
License:Apache License
@Override public void start() { JsonObject requestMsg = new JsonObject(); requestMsg.put("body", "rajith muditha attapattu"); vertx.eventBus().send("hello-service-amqp", requestMsg, this); System.out.println("Client verticle sent request : " + requestMsg.encodePrettily()); }
From source file:PubVerticle.java
License:Apache License
@Override public void start() { JsonObject msg1 = new JsonObject(); msg1.put("vertx.routing-key", "foo.bar"); msg1.put("body", "hello world from foo bar"); vertx.eventBus().publish("vertx.service-amqp.bridge", msg1); System.out.println("Publiser verticle sent msg : " + msg1.encodePrettily()); JsonObject msg2 = new JsonObject(); msg2.put("vertx.routing-key", "foo.baz"); msg2.put("body", "hello world from foo baz"); vertx.eventBus().publish("vertx.service-amqp.bridge", msg2); System.out.println("Publiser verticle sent msg : " + msg2.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);/*from w w w .jav a 2 s .com*/ System.out.println("Server verticle sent reply : " + replyMsg.encodePrettily()); }
From source file:RestAPI.java
private void handleGetProduct(RoutingContext routingContext) { String productID = routingContext.request().getParam("productID"); HttpServerResponse response = routingContext.response(); if (productID == null) { sendError(400, response);/*from w w w .j a va2s . c o m*/ } else { JsonObject product = products.get(productID); if (product == null) { sendError(404, response); } else { response.putHeader("content-type", "application/json").end(product.encodePrettily()); } } }
From source file:app.Main.java
License:Apache License
public static void main(String... args) throws Throwable { Vertx vertx = Vertx.vertx();/*from w w w.ja v a 2s . c om*/ TcpEventBusBridge bridge = TcpEventBusBridge.create(vertx, new BridgeOptions().addInboundPermitted(new PermittedOptions().setAddressRegex("sample.*")) .addOutboundPermitted(new PermittedOptions().setAddressRegex("sample.*"))); vertx.eventBus().consumer("sample.dumb.inbox", message -> { JsonObject body = (JsonObject) message.body(); System.out.println(body.encodePrettily()); }); MessageProducer<Object> tickPublisher = vertx.eventBus().publisher("sample.clock.ticks"); vertx.setPeriodic(1000L, id -> { tickPublisher.send(new JsonObject().put("tick", id)); }); vertx.eventBus().consumer("sample.echo", message -> { JsonObject body = (JsonObject) message.body(); System.out.println("Echoing: " + body.encodePrettily()); message.reply(body); }); bridge.listen(7000, result -> { if (result.failed()) { throw new RuntimeException(result.cause()); } else { System.out.println("TCP Event Bus bridge running on port 7000"); } }); }
From source file:co.runrightfast.vertx.core.impl.VertxServiceImpl.java
License:Apache License
private void logVertxOptions() { LOG.logp(CONFIG, getClass().getName(), "logVertxOptions", () -> { final JsonObject json = new JsonObject() .put("BlockedThreadCheckInterval", vertxOptions.getBlockedThreadCheckInterval()) .put("ClusterHost", vertxOptions.getClusterHost()) .put("ClusterPingInterval", vertxOptions.getClusterPingInterval()) .put("ClusterPingReplyInterval", vertxOptions.getClusterPingReplyInterval()) .put("ClusterPort", vertxOptions.getClusterPort()) .put("EventLoopPoolSize", vertxOptions.getEventLoopPoolSize()) .put("HAGroup", vertxOptions.getHAGroup()) .put("InternalBlockingPoolSize", vertxOptions.getInternalBlockingPoolSize()) .put("MaxEventLoopExecuteTime", vertxOptions.getMaxEventLoopExecuteTime()) .put("MaxWorkerExecuteTime", vertxOptions.getMaxWorkerExecuteTime()) .put("QuorumSize", vertxOptions.getQuorumSize()) .put("WarningExceptionTime", vertxOptions.getWarningExceptionTime()) .put("WorkerPoolSize", vertxOptions.getWorkerPoolSize()); final ClusterManager clusterManager = vertxOptions.getClusterManager(); if (clusterManager != null) { json.put("clusterManagerClass", clusterManager.getClass().getName()); }/*from w w w. java 2 s . co m*/ final MetricsOptions metricsOptions = vertxOptions.getMetricsOptions(); if (metricsOptions != null) { json.put("MetricsOptions", toJsonObject(metricsOptions)); } return json.encodePrettily(); }); }
From source file:com.kumuluz.ee.samples.reactive.vertx.VertxResource.java
License:MIT License
@POST @Path("publish") public Response sendMessage(Message message) { tacos.send(message.getContent());/*from w ww .j a v a 2 s.com*/ JsonObject reponse = new JsonObject().put("message", message.getContent()).put("status", "sent"); return Response.ok(reponse.encodePrettily()).build(); }
From source file:examples.MongoClientExamples.java
License:Open Source License
public void example8(MongoClient mongoClient) { // empty query = match any JsonObject query = new JsonObject(); mongoClient.find("books", query, res -> { if (res.succeeded()) { for (JsonObject json : res.result()) { System.out.println(json.encodePrettily()); }//from w ww .j a v a 2s . c o m } else { res.cause().printStackTrace(); } }); }
From source file:examples.MongoClientExamples.java
License:Open Source License
public void example9(MongoClient mongoClient) { // will match all Tolkien books JsonObject query = new JsonObject().put("author", "J. R. R. Tolkien"); mongoClient.find("books", query, res -> { if (res.succeeded()) { for (JsonObject json : res.result()) { System.out.println(json.encodePrettily()); }//from w ww .j av a2s . co m } else { res.cause().printStackTrace(); } }); }