Example usage for io.vertx.core.json JsonObject JsonObject

List of usage examples for io.vertx.core.json JsonObject JsonObject

Introduction

In this page you can find the example usage for io.vertx.core.json JsonObject JsonObject.

Prototype

public JsonObject() 

Source Link

Document

Create a new, empty instance

Usage

From source file:examples.JDBCDataSourceExamples.java

License:Open Source License

public void example1(ServiceDiscovery discovery) {
    Record record = JDBCDataSource.createRecord("some-data-source-service", // The service name
            new JsonObject().put("url", "some jdbc url"), // The location
            new JsonObject().put("some-metadata", "some-value") // Some metadata
    );/*ww w  .ja v a2  s  . c om*/

    discovery.publish(record, ar -> {
        // ...
    });
}

From source file:examples.JDBCDataSourceExamples.java

License:Open Source License

public void example2(ServiceDiscovery discovery) {
    // Get the record
    discovery.getRecord(new JsonObject().put("name", "some-data-source-service"), ar -> {
        if (ar.succeeded() && ar.result() != null) {
            // Retrieve the service reference
            ServiceReference reference = discovery.getReferenceWithConfiguration(ar.result(), // The record
                    new JsonObject().put("username", "clement").put("password", "*****")); // Some additional metadata

            // Retrieve the service object
            JDBCClient client = reference.get();

            // ...

            // when done
            reference.release();//from   w w  w  .  j  av a 2  s.  com
        }
    });
}

From source file:examples.JDBCDataSourceExamples.java

License:Open Source License

public void example3(ServiceDiscovery discovery) {
    JDBCDataSource.<JsonObject>getJDBCClient(discovery,
            new JsonObject().put("name", "some-data-source-service"),
            new JsonObject().put("username", "clement").put("password", "*****"), // Some additional metadata
            ar -> {/* w ww .  ja  v  a 2 s  . c  om*/
                if (ar.succeeded()) {
                    JDBCClient client = ar.result();

                    // ...

                    // Dont' forget to release the service
                    ServiceDiscovery.releaseServiceObject(discovery, client);

                }
            });
}

From source file:examples.limited.MessageSourceExamples.java

License:Open Source License

public void example1(ServiceDiscovery discovery) {
    Record record1 = MessageSource.createRecord("some-message-source-service", // The service name
            "some-address", // The event bus address
            JsonObject.class // The message payload type
    );//  www.ja  v a2  s .  c o  m

    Record record2 = MessageSource.createRecord("some-other-message-source-service", // The service name
            "some-address", // The event bus address
            JsonObject.class, // The message payload type
            new JsonObject().put("some-metadata", "some value"));
}

From source file:examples.MessageSourceExamples.java

License:Open Source License

public void example2(ServiceDiscovery discovery) {
    // Get the record
    discovery.getRecord(new JsonObject().put("name", "some-message-source-service"), ar -> {
        if (ar.succeeded() && ar.result() != null) {
            // Retrieve the service reference
            ServiceReference reference = discovery.getReference(ar.result());
            // Retrieve the service object
            MessageConsumer<JsonObject> consumer = reference.get();

            // Attach a message handler on it
            consumer.handler(message -> {
                // message handler
                JsonObject payload = message.body();
            });//from  ww w.j av a2  s .c o  m

            // ...
            // when done
            reference.release();
        }
    });
}

From source file:examples.MessageSourceExamples.java

License:Open Source License

public void example3(ServiceDiscovery discovery) {
    MessageSource.<JsonObject>getConsumer(discovery,
            new JsonObject().put("name", "some-message-source-service"), ar -> {
                if (ar.succeeded()) {
                    MessageConsumer<JsonObject> consumer = ar.result();

                    // Attach a message handler on it
                    consumer.handler(message -> {
                        // message handler
                        JsonObject payload = message.body();
                    });//from w w  w .j  a v  a2 s .com
                    // ...

                    // Dont' forget to release the service
                    ServiceDiscovery.releaseServiceObject(discovery, consumer);

                }
            });
}

From source file:examples.MongoClientExamples.java

License:Open Source License

public void example1(MongoClient mongoClient) {
    // Document has no id
    JsonObject document = new JsonObject().put("title", "The Hobbit");
    mongoClient.save("books", document, res -> {
        if (res.succeeded()) {
            String id = res.result();
            System.out.println("Saved book with id " + id);
        } else {//www  .  ja  va2  s  .  c om
            res.cause().printStackTrace();
        }
    });
}

From source file:examples.MongoClientExamples.java

License:Open Source License

public void example2(MongoClient mongoClient) {
    // Document has an id already
    JsonObject document = new JsonObject().put("title", "The Hobbit").put("_id", "123244");
    mongoClient.save("books", document, res -> {
        if (res.succeeded()) {
            // ...
        } else {/*  ww  w.j  av  a 2  s  .c om*/
            res.cause().printStackTrace();
        }
    });
}

From source file:examples.MongoClientExamples.java

License:Open Source License

public void example3(MongoClient mongoClient) {
    // Document has an id already
    JsonObject document = new JsonObject().put("title", "The Hobbit");
    mongoClient.insert("books", document, res -> {
        if (res.succeeded()) {
            String id = res.result();
            System.out.println("Inserted book with id " + id);
        } else {/*w  w w  . j av  a2s.  co  m*/
            res.cause().printStackTrace();
        }
    });
}

From source file:examples.MongoClientExamples.java

License:Open Source License

public void example4(MongoClient mongoClient) {
    // Document has an id already
    JsonObject document = new JsonObject().put("title", "The Hobbit").put("_id", "123244");
    mongoClient.insert("books", document, res -> {
        if (res.succeeded()) {
            //...
        } else {/*from w w w  .ja  v a 2s . c o  m*/
            // Will fail if the book with that id already exists.
        }
    });
}