當前位置: 首頁>>代碼示例>>Java>>正文


Java Message.body方法代碼示例

本文整理匯總了Java中io.vertx.core.eventbus.Message.body方法的典型用法代碼示例。如果您正苦於以下問題:Java Message.body方法的具體用法?Java Message.body怎麽用?Java Message.body使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.vertx.core.eventbus.Message的用法示例。


在下文中一共展示了Message.body方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: searchLabels

import io.vertx.core.eventbus.Message; //導入方法依賴的package包/類
/**
 * Consumer for Event Bus Messages requesting labels
 *
 * @param msg
 */
void searchLabels(Message<JsonObject> msg) {

    final JsonObject sq = msg.body();
    LOG.debug("{}\n{}", address, sq.encodePrettily());

    //extract the string query
    final String query = "select metric".equals(sq.getString("target")) ? "" : sq.getString("target");
    if (lastQueriesUpdate.get() + 60000 < System.currentTimeMillis() || this.queries.isEmpty()) {

        //retrieve list of unique names
        client.distinct(collectionName, "t.name", String.class.getName(), result -> {
            if (result.succeeded()) {
                this.queries = result.result().stream().map(o -> (String) o).collect(toList());
                this.lastQueriesUpdate.set(System.currentTimeMillis());
            } else {
                LOG.error("Query for labels failed", result.cause());
            }
            msg.reply(this.queries.stream().filter(q -> q.startsWith(query)).collect(toJsonArray()));
        });
    } else {
        msg.reply(this.queries.stream().filter(q -> q.startsWith(query)).collect(toJsonArray()));
    }
}
 
開發者ID:gmuecke,項目名稱:grafana-vertx-datasource,代碼行數:29,代碼來源:LabelVerticle.java

示例2: handle

import io.vertx.core.eventbus.Message; //導入方法依賴的package包/類
public void handle(Message<JsonObject> msg) {
  try {
    JsonObject json = msg.body();
    String action = msg.headers().get("action");
    if (action == null) {
      throw new IllegalStateException("action not specified");
    }
    accessed();
    switch (action) {
      case "createNotification": {
        service.createNotification(createHandler(msg));
        break;
      }
      default: {
        throw new IllegalStateException("Invalid action: " + action);
      }
    }
  } catch (Throwable t) {
    msg.reply(new ServiceException(500, t.getMessage()));
    throw t;
  }
}
 
開發者ID:pflima92,項目名稱:jspare-vertx-ms-blueprint,代碼行數:23,代碼來源:NotificationServiceVertxProxyHandler.java

示例3: generate

import io.vertx.core.eventbus.Message; //導入方法依賴的package包/類
public void generate(Message<JsonObject> message) {
    JsonObject metadata = message.body();
    String build = metadata.getString("build", "maven");
    String language = metadata.getString("language", "java");
    //Act as a activation flags in .gitignore
    metadata.put(build, true);
    metadata.put(language, true);
    String baseDir = metadata.getString("baseDir");
    CompositeFuture.all(
        generateFile(metadata, baseDir, BUILD.get(build)),
        generateFile(metadata, baseDir, LANGUAGES.get(language)),
        generateFile(metadata, baseDir, ".gitignore"),
        generateFile(metadata, baseDir, ".editorconfig")
    ).setHandler(ar -> {
        if (ar.failed()) {
            log.error("Impossible to generate project {} : {}", metadata, ar.cause().getMessage());
            message.fail(500, ar.cause().getMessage());
        } else {
            message.reply(null);
        }
    });
}
 
開發者ID:danielpetisme,項目名稱:vertx-forge,代碼行數:23,代碼來源:ProjectGeneratorService.java

示例4: handle

import io.vertx.core.eventbus.Message; //導入方法依賴的package包/類
public void handle(Message<JsonObject> msg) {
  try {
    JsonObject json = msg.body();
    String action = msg.headers().get("action");
    if (action == null) {
      throw new IllegalStateException("action not specified");
    }
    accessed();
    switch (action) {
      case "getConfiguration": {
        service.getConfiguration((java.lang.String)json.getValue("name"), createHandler(msg));
        break;
      }
      default: {
        throw new IllegalStateException("Invalid action: " + action);
      }
    }
  } catch (Throwable t) {
    msg.reply(new ServiceException(500, t.getMessage()));
    throw t;
  }
}
 
開發者ID:pflima92,項目名稱:jspare-vertx-ms-blueprint,代碼行數:23,代碼來源:ConfigurationProviderVertxProxyHandler.java

示例5: findAll

import io.vertx.core.eventbus.Message; //導入方法依賴的package包/類
public void findAll(Message<JsonObject> message) {
    JsonObject query = message.body();
    if (dependencies != null) {
        message.reply(dependencies);
    } else {
        message.fail(500, "Impossible to retrieve dependencies");
    }
}
 
開發者ID:danielpetisme,項目名稱:vertx-forge,代碼行數:9,代碼來源:DependencyService.java

示例6: registerPostprocessing

import io.vertx.core.eventbus.Message; //導入方法依賴的package包/類
/**
 * Register a single postprocessing eventbus address, only a single post-processor supported at the moment.
 *
 * @param msg
 */
void registerPostprocessing(final Message<String> msg) {

    String ppAddress = msg.body();
    LOG.info("Registering postprocessing at {}", ppAddress);
    this.postProcessingAddress = ppAddress;
}
 
開發者ID:gmuecke,項目名稱:grafana-vertx-datasource,代碼行數:12,代碼來源:SplitMergeTimeSeriesVerticle.java

示例7: handle

import io.vertx.core.eventbus.Message; //導入方法依賴的package包/類
public void handle(Message<JsonObject> msg) {
  try {
    JsonObject json = msg.body();
    String action = msg.headers().get("action");
    if (action == null) {
      throw new IllegalStateException("action not specified");
    }
    accessed();
    switch (action) {
      case "send": {
        service.send(json.getJsonObject("message") == null ? null : new io.vertx.ext.mail.MailMessage(json.getJsonObject("message")), 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;
  }
}
 
開發者ID:pflima92,項目名稱:jspare-vertx-ms-blueprint,代碼行數:33,代碼來源:MailServiceVertxProxyHandler.java

示例8: createPage

import io.vertx.core.eventbus.Message; //導入方法依賴的package包/類
private void createPage(Message<JsonObject> message) {
  JsonObject request = message.body();
  JsonArray data = new JsonArray()
    .add(request.getString("title"))
    .add(request.getString("markdown"));

  dbClient.updateWithParams(sqlQueries.get(SqlQuery.CREATE_PAGE), data, res -> {
    if (res.succeeded()) {
      message.reply("ok");
    } else {
      reportQueryError(message, res.cause());
    }
  });
}
 
開發者ID:vert-x3,項目名稱:vertx-guide-for-java-devs,代碼行數:15,代碼來源:WikiDatabaseVerticle.java

示例9: savePage

import io.vertx.core.eventbus.Message; //導入方法依賴的package包/類
private void savePage(Message<JsonObject> message) {
  JsonObject request = message.body();
  JsonArray data = new JsonArray()
    .add(request.getString("markdown"))
    .add(request.getString("id"));

  dbClient.updateWithParams(sqlQueries.get(SqlQuery.SAVE_PAGE), data, res -> {
    if (res.succeeded()) {
      message.reply("ok");
    } else {
      reportQueryError(message, res.cause());
    }
  });
}
 
開發者ID:vert-x3,項目名稱:vertx-guide-for-java-devs,代碼行數:15,代碼來源:WikiDatabaseVerticle.java

示例10: request

import io.vertx.core.eventbus.Message; //導入方法依賴的package包/類
protected T request(
        final Message<Envelop> message,
        final Integer index,
        final Class<T> clazz) {
    final Envelop body = message.body();
    return Fn.getSemi(null == body, this.getLogger(), Fn::nil,
            () -> body.data(index, clazz));
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:9,代碼來源:BaseImitate.java

示例11: request

import io.vertx.core.eventbus.Message; //導入方法依賴的package包/類
static <T> T request(
        final Message<Envelop> message,
        final Class<T> clazz
) {
    final Envelop body = message.body();
    return Fn.getSemi(null == body, null, Fn::nil,
            () -> body.data(clazz));
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:9,代碼來源:In.java

示例12: success

import io.vertx.core.eventbus.Message; //導入方法依賴的package包/類
protected Envelop success(final String address,
                          final AsyncResult<Message<Envelop>> handler
) {
    Envelop envelop;
    try {
        final Message<Envelop> message = handler.result();
        envelop = message.body();
    } catch (final Throwable ex) {
        final WebException error
                = new _500EntityCastException(this.getClass(),
                address, ex.getMessage());
        envelop = Envelop.failure(error);
    }
    return envelop;
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:16,代碼來源:BaseAim.java

示例13: clean

import io.vertx.core.eventbus.Message; //導入方法依賴的package包/類
public void clean(Message<JsonObject> message) {
  JsonObject metadata = message.body();
  String rootDir = metadata.getString("rootDir");
  vertx.fileSystem().deleteRecursive(rootDir, true, ar -> {
    if (ar.failed()) {
      log.error("Impossible to delete temp directory {}: {}", rootDir, ar.cause().getMessage());
    } else {
      log.debug("Temp directory {} deleted", rootDir);
    }
  });

}
 
開發者ID:vert-x3,項目名稱:vertx-starter,代碼行數:13,代碼來源:StarterService.java

示例14: queryTimeSeries

import io.vertx.core.eventbus.Message; //導入方法依賴的package包/類
/**
 * Searches datapoints within range and for selected targets
 *
 * @param msg
 */
void queryTimeSeries(final Message<JsonObject> msg) {

    final JsonObject query = msg.body();
    LOG.debug("{}\n{}", address, query.encodePrettily());

    // get the paramsters from the query
    final Range range = rangeParser.parse(query.getJsonObject("range").getString("from"),
            query.getJsonObject("range").getString("to"));
    final long interval = intervalParser.parseToLong(query.getString("interval"));
    final JsonArray targets = query.getJsonArray("targets")
                                   .stream()
                                   .map(o -> ((JsonObject) o).getString("target"))
                                   .collect(toJsonArray());

    //build the query and options
    final JsonObject tsQuery = $and(obj("n.begin", $gte(range.getStart())),
            obj("n.begin", $lte(range.getEnd())),
            obj("t.name", $in(targets)));

    final FindOptions findOptions = new FindOptions().setFields(obj().put("t.name", 1)
                                                                     .put("n.begin", 1)
                                                                     .put("n.value", 1)
                                                                     .put("_id", 0)).setSort(obj("n.begin", 1));

    long start = System.currentTimeMillis();
    //execute search and process response
    client.findWithOptions(collectionName, tsQuery, findOptions, result -> {

        if (result.succeeded()) {
            JsonArray resp = processResponse(range, r -> range.splitEvery(interval), targets, result);
            long end = System.currentTimeMillis();
            LOG.debug(
                    "Sending response with {} timeseries and {} datapoints (after {} ms)",
                    resp.size(),
                    resp.stream()
                        .map(o -> ((JsonObject) o).getJsonArray("datapoints"))
                        .collect(Collectors.summingInt(JsonArray::size)),
                    (end - start));
            msg.reply(resp);

        } else {
            LOG.error("Annotation query failed", result.cause());
            msg.reply(arr());
        }

    });
}
 
開發者ID:gmuecke,項目名稱:grafana-vertx-datasource,代碼行數:53,代碼來源:PercentilesVerticle.java

示例15: queryTimeSeries

import io.vertx.core.eventbus.Message; //導入方法依賴的package包/類
/**
 * Searches datapoints within range and for selected targets
 *
 * @param msg
 */
void queryTimeSeries(final Message<JsonObject> msg) {

    final JsonObject query = msg.body();
    LOG.debug("{}\n{}", address, query.encodePrettily());

    // get the paramsters from the query
    final Range range = rangeParser.parse(query.getJsonObject("range").getString("from"),
                                          query.getJsonObject("range").getString("to"));
    final JsonArray targets = query.getJsonArray("targets")
                                   .stream()
                                   .map(o -> ((JsonObject) o).getString("target"))
                                   .collect(toJsonArray());

    //build the query and options
    final JsonObject tsQuery = $and(obj("n.begin", $gte(range.getStart())),
                                    obj("n.begin", $lte(range.getEnd())),
                                    obj("t.name", $in(targets)));

    final FindOptions findOptions = new FindOptions().setFields(obj().put("t.name", 1)
                                                                     .put("n.begin", 1)
                                                                     .put("n.value", 1)
                                                                     .put("_id", 0)).setSort(obj("n.begin", 1));

    long start = System.currentTimeMillis();
    //execute search and process response
    client.findWithOptions(collectionName, tsQuery, findOptions, result -> {
        long end = System.currentTimeMillis();
        if (result.succeeded()) {
            JsonArray response = targets.stream()
                                        //  every timeseries is an {"target": label, "datapoints": [[value, ts],... ]}
                                        .map(target -> obj().put("target", target)
                                                            .put("datapoints",
                                                                 result.result()
                                                                       .stream()
                                                                       .filter(r -> target.equals(r.getJsonObject(
                                                                               "t").getString("name")))
                                                                       .map(json -> json.getJsonObject("n"))
                                                                       //produce a grafana json datapoint [value,timestamp]
                                                                       .map(dp -> arr(dp.getLong("value"),
                                                                                      dp.getLong("begin")))
                                                                       //collect all datapoint arrays to an array of arrays
                                                                       .collect(toJsonArray())))
                                        .collect(toJsonArray());
            LOG.debug("Sending response with {} timeseries and {} datapoints (after {} ms)",
                      response.size(),
                      response.stream()
                              .map(o -> ((JsonObject) o).getJsonArray("datapoints"))
                              .collect(Collectors.summingInt(JsonArray::size)),
                      (end - start));
            msg.reply(response);
        } else {
            LOG.error("Annotation query failed", result.cause());
            msg.reply(arr());
        }
    });
}
 
開發者ID:gmuecke,項目名稱:grafana-vertx-datasource,代碼行數:62,代碼來源:SimpleTimeSeriesVerticle.java


注:本文中的io.vertx.core.eventbus.Message.body方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。