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:co.runrightfast.vertx.demo.testHarness.jmx.DemoMXBeanImpl.java

License:Apache License

void handleEchoRequest(final Message<String> request) {
    log.info("*** RECIEVED MESSAGE : " + request.body());
    MessageHeader.getReplyToAddress(request).ifPresent(replyTo -> {
        vertx.eventBus().send(replyTo,//  w ww .j  a v  a 2s .  co  m
                String.format("%s: RECEIVED MESSAGE: %s", Instant.now(), request.body()));
    });
}

From source file:co.runrightfast.vertx.demo.testHarness.jmx.DemoMXBeanImpl.java

License:Apache License

void handleEchoResponse(final Message<String> responseMessage) {
    log.info(responseMessage.body());
}

From source file:co.runrightfast.vertx.demo.testHarness.jmx.DemoMXBeanImpl.java

License:Apache License

void handleGetVerticleDeploymentsResponse(final Message<GetVerticleDeployments.Response> responseMessage) {
    final GetVerticleDeployments.Response response = responseMessage.body();
    final JsonObject json = Json.createObjectBuilder().add("headers", toJsonObject(responseMessage.headers()))
            .add("body", ProtobufUtils.protobuMessageToJson(response)).build();
    log.info(JsonUtils.toVertxJsonObject(json).encodePrettily());
}

From source file:com.appdocker.iop.InternetOfPeopleServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {/*from  ww  w.j  av a2 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 "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

/**
 * Convert the event bus message to a metric object we can work with.
 *
 * @param message the event bus message//from  ww  w.  jav a  2s. c  o m
 * @return a metric object that can be sent to Bosun
 */
private OpenTsDbMetric getMetricFromMessage(Message<JsonObject> message) {
    OpenTsDbMetric metric = null;
    try {
        metric = new OpenTsDbMetric(message.body());
    } catch (IllegalArgumentException ex) {
        sendError(message, ex.getMessage());
        return null;
    }

    if (!metric.validate(maxTags)) {
        sendError(message,
                String.format("Cannot send more than %d tags, %d were attempted", maxTags, metric.tags.size()));
        metric = null;
    }
    return metric;
}

From source file:com.cyngn.vertx.bosun.BosunReporter.java

License:Apache License

/**
 * Handles processing metric requests off the event bus
 *
 * @param message the metrics message//from w w  w  .  j  a  v  a  2s  . c om
 */
@Override
public void handle(Message<JsonObject> message) {
    String action = message.body().getString(ACTION_FIELD);

    if (action == null) {
        sendError(message, "You must specify an action");
    }

    Consumer<Message<JsonObject>> handler = handlers.get(action);

    if (handler != null) {
        handler.accept(message);
    } else {
        sendError(message, "Invalid action: " + action + " specified.");
    }
}

From source file:com.cyngn.vertx.opentsdb.service.OpenTsDbService.java

License:Apache License

private void processMetricBatch(Message<JsonObject> message) {
    JsonArray metricsObjects = message.body().getJsonArray(MetricsParser.METRICS_FIELD);

    if (metricsObjects == null) {
        String errMsg = String.format("invalid batch message request no 'metrics' field supplied, msg: %s",
                message.body());//from  w  w  w .  j  a  v a  2s  .c  o m
        logger.warn(errMsg);
        sendError(message, errMsg);
    }

    // roll through and add all the metrics
    for (int i = 0; i < metricsObjects.size(); i++) {
        String metric = metricsParser.createMetricString(message, metricsObjects.getJsonObject(i));
        if (metric != null) {
            if (!addMetric(null, metric)) {
                reportFullBacklog(message);
                break;
            }
        } else {
            // something is bad in the batch, the parsers error handler will reply to the message as failed
            return;
        }
    }
    message.reply(OK_REPLY);
}

From source file:com.cyngn.vertx.opentsdb.service.OpenTsDbService.java

License:Apache License

private void processMetric(Message<JsonObject> message) {
    final JsonObject tags = message.body().getJsonObject(MetricsParser.TAGS_FIELD);
    if (hasInvalidTags(tags)) {
        // the metric will be rejected by TSD, so don't even send it
        sendError(message, "You specified too many tags");
        return;/*from ww  w.  j a va  2 s  .  co  m*/
    }

    String metricStr = metricsParser.createMetricString(message, message.body());
    if (metricStr != null) {
        addMetric(message, metricStr);
    }
}

From source file:com.diabolicallabs.process.manager.service.KnowledgeServiceFactoryVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {//  w ww  .  j  a v a2  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 "getKnowledgeService": {
            service.getKnowledgeService(res -> {
                if (res.failed()) {
                    if (res.cause() instanceof ServiceException) {
                        msg.reply(res.cause());
                    } else {
                        msg.reply(new ServiceException(-1, res.cause().getMessage()));
                    }
                } else {
                    String proxyAddress = UUID.randomUUID().toString();
                    ProxyHelper.registerService(KnowledgeService.class, vertx, res.result(), proxyAddress,
                            false, timeoutSeconds);
                    msg.reply(null, new DeliveryOptions().addHeader("proxyaddr", proxyAddress));
                }
            });
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.reply(new ServiceException(500, t.getMessage()));
        throw t;
    }
}

From source file:com.diabolicallabs.process.manager.service.KnowledgeServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {/* www . 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 "addClassPathResource": {
            service.addClassPathResource((java.lang.String) json.getValue("resourceName"), createHandler(msg));
            break;
        }
        case "addFileResource": {
            service.addFileResource((java.lang.String) json.getValue("fileName"), createHandler(msg));
            break;
        }
        case "processDefinitions": {
            service.processDefinitions(createHandler(msg));
            break;
        }
        case "getProcessService": {
            service.getProcessService(res -> {
                if (res.failed()) {
                    if (res.cause() instanceof ServiceException) {
                        msg.reply(res.cause());
                    } else {
                        msg.reply(new ServiceException(-1, res.cause().getMessage()));
                    }
                } else {
                    String proxyAddress = UUID.randomUUID().toString();
                    ProxyHelper.registerService(ProcessService.class, vertx, res.result(), proxyAddress, false,
                            timeoutSeconds);
                    msg.reply(null, new DeliveryOptions().addHeader("proxyaddr", proxyAddress));
                }
            });
            break;
        }
        case "getRuleService": {
            service.getRuleService(res -> {
                if (res.failed()) {
                    if (res.cause() instanceof ServiceException) {
                        msg.reply(res.cause());
                    } else {
                        msg.reply(new ServiceException(-1, res.cause().getMessage()));
                    }
                } else {
                    String proxyAddress = UUID.randomUUID().toString();
                    ProxyHelper.registerService(RuleService.class, vertx, res.result(), proxyAddress, false,
                            timeoutSeconds);
                    msg.reply(null, new DeliveryOptions().addHeader("proxyaddr", proxyAddress));
                }
            });
            break;
        }
        case "getTaskService": {
            service.getTaskService(res -> {
                if (res.failed()) {
                    if (res.cause() instanceof ServiceException) {
                        msg.reply(res.cause());
                    } else {
                        msg.reply(new ServiceException(-1, res.cause().getMessage()));
                    }
                } else {
                    String proxyAddress = UUID.randomUUID().toString();
                    ProxyHelper.registerService(TaskService.class, vertx, res.result(), proxyAddress, false,
                            timeoutSeconds);
                    msg.reply(null, new DeliveryOptions().addHeader("proxyaddr", proxyAddress));
                }
            });
            break;
        }
        case "getTaskServiceAddress": {
            service.getTaskServiceAddress(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;
    }
}