Example usage for io.vertx.core.eventbus Message body

List of usage examples for io.vertx.core.eventbus Message body

Introduction

In this page you can find the example usage for io.vertx.core.eventbus Message body.

Prototype

@CacheReturn
T body();

Source Link

Document

The body of the message.

Usage

From source file:com.englishtown.vertx.mail.MailServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {/*from  w w w  .  ja v a  2 s  . com*/
        JsonObject json = msg.body();
        String action = msg.headers().get("action");
        if (action == null) {
            throw new IllegalStateException("action not specified");
        }
        accessed();
        switch (action) {

        case "start": {
            service.start();
            break;
        }
        case "stop": {
            service.stop();
            break;
        }
        case "send": {
            service.send(
                    json.getJsonObject("options") == null ? null
                            : new com.englishtown.vertx.mail.SendOptions(json.getJsonObject("options")),
                    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:com.englishtown.vertx.solr.SolrServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {// www .j  a  v  a 2 s  .c  om
        JsonObject json = msg.body();
        String action = msg.headers().get("action");
        if (action == null) {
            throw new IllegalStateException("action not specified");
        }
        accessed();
        switch (action) {

        case "start": {
            service.start();
            break;
        }
        case "stop": {
            service.stop();
            break;
        }
        case "query": {
            service.query((io.vertx.core.json.JsonObject) json.getValue("query"),
                    json.getJsonObject("options") == null ? null
                            : new com.englishtown.vertx.solr.QueryOptions(json.getJsonObject("options")),
                    createHandler(msg));
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.fail(-1, t.getMessage());
        throw t;
    }
}

From source file:com.example.myservice.services.ProductServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    JsonObject json = msg.body();
    String action = msg.headers().get("action");
    if (action == null) {
        throw new IllegalStateException("action not specified");
    }//from w  w w .  ja  va 2  s.co  m
    accessed();
    switch (action) {

    case "start": {
        service.start();
        break;
    }
    case "stop": {
        service.stop();
        break;
    }
    case "list": {
        service.list(createHandler(msg));
        break;
    }
    default: {
        throw new IllegalStateException("Invalid action: " + action);
    }
    }
}

From source file:com.github.ithildir.airbot.service.GeoServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {//from www  .  ja v  a 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 "getLocationByCoordinates": {
            service.getLocationByCoordinates(
                    json.getValue("latitude") == null ? null : (json.getDouble("latitude").doubleValue()),
                    json.getValue("longitude") == null ? null : (json.getDouble("longitude").doubleValue()),
                    res -> {
                        if (res.failed()) {
                            if (res.cause() instanceof ServiceException) {
                                msg.reply(res.cause());
                            } else {
                                msg.reply(new ServiceException(-1, res.cause().getMessage()));
                            }
                        } else {
                            msg.reply(res.result() == null ? null : res.result().toJson());
                        }
                    });
            break;
        }
        case "getLocationByQuery": {
            service.getLocationByQuery((java.lang.String) json.getValue("query"), res -> {
                if (res.failed()) {
                    if (res.cause() instanceof ServiceException) {
                        msg.reply(res.cause());
                    } else {
                        msg.reply(new ServiceException(-1, res.cause().getMessage()));
                    }
                } else {
                    msg.reply(res.result() == null ? null : res.result().toJson());
                }
            });
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.reply(new ServiceException(500, t.getMessage()));
        throw t;
    }
}

From source file:com.github.ithildir.airbot.service.MeasurementServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {/*from  www. j a  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 "getMeasurement": {
            service.getMeasurement(
                    json.getValue("latitude") == null ? null : (json.getDouble("latitude").doubleValue()),
                    json.getValue("longitude") == null ? null : (json.getDouble("longitude").doubleValue()),
                    res -> {
                        if (res.failed()) {
                            if (res.cause() instanceof ServiceException) {
                                msg.reply(res.cause());
                            } else {
                                msg.reply(new ServiceException(-1, res.cause().getMessage()));
                            }
                        } else {
                            msg.reply(res.result() == null ? null : res.result().toJson());
                        }
                    });
            break;
        }
        case "getName": {
            service.getName(createHandler(msg));
            break;
        }
        case "init": {
            service.init(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:com.github.ithildir.airbot.service.UserServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {// w  ww .j a  va  2s . com
        JsonObject json = msg.body();
        String action = msg.headers().get("action");
        if (action == null) {
            throw new IllegalStateException("action not specified");
        }
        accessed();
        switch (action) {

        case "getUserLocation": {
            service.getUserLocation((java.lang.String) json.getValue("userId"), res -> {
                if (res.failed()) {
                    if (res.cause() instanceof ServiceException) {
                        msg.reply(res.cause());
                    } else {
                        msg.reply(new ServiceException(-1, res.cause().getMessage()));
                    }
                } else {
                    msg.reply(res.result() == null ? null : res.result().toJson());
                }
            });
            break;
        }
        case "updateUserLocation": {
            service.updateUserLocation((java.lang.String) json.getValue("userId"),
                    json.getValue("latitude") == null ? null : (json.getDouble("latitude").doubleValue()),
                    json.getValue("longitude") == null ? null : (json.getDouble("longitude").doubleValue()),
                    (java.lang.String) json.getValue("country"), 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:com.github.jackygurui.vertxredissonrepository.handler.Impl.CallInMessageHandlerImpl.java

License:Apache License

@Override
public void handle(Message<JsonObject> m) {
    JsonObject jBody = m.body();
    String from = jBody.getString("from");
    String to = jBody.getString("to");
    Long requestTime = jBody.getLong("requestTime");
    String userData = jBody.getString("userData");
    AtomicReference<String> cId = new AtomicReference();
    AtomicReference<Customer.PersonalDetails> p = new AtomicReference();
    Async.waterfall().<String>task(t -> {
        personalDetailsRepo.searchUniqueIndex("phoneNumber", from, t);
    }).<Customer.PersonalDetails>task((id, t) -> {
        cId.set(id);//from   ww  w  .  ja v  a2s.c  o  m
        personalDetailsRepo.get(id, t);
    }).<Customer.AddressDetails>task((c, t) -> {
        p.set(c);
        addressDetailsRepo.get(cId.get(), t);
    }).run(r -> {
        CallIn ci;
        if (r.failed()) {
            ci = CallIn.builder().callTime(requestTime).callType(numberTypeMap.get(to)).comments(userData)
                    .fullName("??").phoneNumber(from).build();
        } else {
            Customer.PersonalDetails cpd = p.get();
            Customer.AddressDetails cad = r.result();
            ci = CallIn.builder().address(cad.getFullAddress()).area(cpd.getArea()).birthDay(cpd.getBirthDay())
                    .callTime(requestTime).callType(numberTypeMap.get(to)).city(cpd.getCity())
                    .comments(userData).customerId(cId.get()).fullName(cpd.getFullName())
                    .gender(cpd.getGender()).phoneNumber(from).province(cpd.getProvince()).type(cpd.getType())
                    .build();
        }
        callInRepo.create(Json.encode(ci), c -> {
            m.reply(c.result());
            ci.setId(c.result());
            vertx.eventBus().publish("client.notification.inComingCall", Json.encode(ci));
        });
    });
}

From source file:com.github.meshuga.vertx.neo4j.rbac.auth.AuthServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    JsonObject json = msg.body();
    String action = msg.headers().get("action");
    if (action == null) {
        throw new IllegalStateException("action not specified");
    }/*from   www . j  a v a  2  s .co m*/
    accessed();
    switch (action) {

    case "hasPermission": {
        service.hasPermission((java.lang.String) json.getValue("userName"),
                (java.lang.String) json.getValue("permission"), createHandler(msg));
        break;
    }
    default: {
        throw new IllegalStateException("Invalid action: " + action);
    }
    }
}

From source file:com.github.vertx.node.example.HelloWorldServiceInterfaceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {/*from  w  w w  .j  a  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 "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.fail(-1, t.getMessage());
        throw t;
    }
}

From source file:com.glencoesoftware.omero.ms.core.RedisCacheVerticle.java

License:Open Source License

/**
 * Get a key from the cache.//from  w ww . j a  v  a 2 s.c  o  m
 */
private void get(Message<String> message) {
    if (connection == null) {
        log.debug("Cache not enabled");
        message.reply(null);
        return;
    }

    String key = message.body();
    if (key == null) {
        message.reply(null);
        return;
    }
    log.debug("Getting cache key: {}", key);

    RedisAsyncCommands<byte[], byte[]> commands = connection.async();
    final StopWatch t0 = new Slf4JStopWatch("get");
    // Binary retrieval, get(String) includes a UTF-8 step
    RedisFuture<byte[]> future = commands.get(key.getBytes());
    future.whenComplete((v, t) -> {
        try {
            if (t != null) {
                log.error("Exception while getting cache value", t);
                message.fail(500, t.getMessage());
                return;
            }
            message.reply(v);
        } finally {
            t0.stop();
        }
    });
}