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


Java Message類代碼示例

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


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

示例1: createSetCharHandler

import io.vertx.core.eventbus.Message; //導入依賴的package包/類
private Handler<AsyncResult<Set<Character>>> createSetCharHandler(Message msg) {
  return res -> {
    if (res.failed()) {
      if (res.cause() instanceof ServiceException) {
        msg.reply(res.cause());
      } else {
        msg.reply(new ServiceException(-1, res.cause().getMessage()));
      }
    } else {
      JsonArray arr = new JsonArray();
      for (Character chr: res.result()) {
        arr.add((int) chr);
      }
      msg.reply(arr);
    }
  };
}
 
開發者ID:pflima92,項目名稱:jspare-vertx-ms-blueprint,代碼行數:18,代碼來源:ConfigurationProviderVertxProxyHandler.java

示例2: processEntries

import io.vertx.core.eventbus.Message; //導入依賴的package包/類
private void processEntries(Message<JsonArray> message) {

		long start = System.currentTimeMillis();
		vertx.executeBlocking(future -> {

			JsonArray entries = message.body();

			for (Object obj : entries.getList()) {
				JsonObject jobj = (JsonObject) obj;
				HEElementModel model = gson.fromJson(jobj.toString(), HEElementModel.class);

				this.getCache(cacheName).put(model.getGuid(), model);
			}

			future.complete();
		}, res -> {
			long stop = System.currentTimeMillis();
			log.info(String.format(PUT_MSG_FORMAT, stop - start));
		});
	}
 
開發者ID:benemon,項目名稱:he-rss-poll,代碼行數:21,代碼來源:JDGPutVerticle.java

示例3: 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

示例4: processFills

import io.vertx.core.eventbus.Message; //導入依賴的package包/類
private Handler<Message<JsonObject>> processFills() {
    return msg -> {
    	try{
         OrderBookUpdate update = msg.body().mapTo(OrderBookUpdate.class);
         
for(OrderFillDTO fill : update.getFills()){
	currentTick.add(fill);
	
}

    	} catch(Exception e){
    		e.printStackTrace();
    		System.out.println("Failed processing fills");
    	}
    };
}
 
開發者ID:AlxGDev,項目名稱:BittrexGatherer,代碼行數:17,代碼來源:BittrexPriceVerticle.java

示例5: processFillsAndSave

import io.vertx.core.eventbus.Message; //導入依賴的package包/類
private Handler<Message<JsonObject>> processFillsAndSave() {
    return msg -> vertx.<String>executeBlocking(future -> {
    	try{
         OrderBookUpdate update = msg.body().mapTo(OrderBookUpdate.class);
         
for(OrderFillDTO fill : update.getFills()){
	currentTick.add(fill);
	service.save(fill, tradingPair, "bittrex");
}
future.complete();
    	} catch(Exception e){
    		e.printStackTrace();
    		future.fail(e);
    	}
    }, result -> {
        if (result.succeeded()) {
            //System.out.println("Done processing fills");
        } else {
        	result.cause().printStackTrace();
        	System.out.println("Failed processing fills");
        }
    });
}
 
開發者ID:AlxGDev,項目名稱:BittrexGatherer,代碼行數:24,代碼來源:BittrexPriceVerticle.java

示例6: processInit

import io.vertx.core.eventbus.Message; //導入依賴的package包/類
private Handler<Message<JsonObject>> processInit() {
    return msg -> {
    	try{
         JsonObject payload = msg.body();
         JsonArray buys = payload.getJsonArray("Buys");
         
for(int i = 0; i<buys.size();i++){
	orderBook.getBuyOrders().put(buys.getJsonObject(i).getDouble("Rate"), buys.getJsonObject(i).getDouble("Quantity"));
}
JsonArray sells = payload.getJsonArray("Sells");
for(int i = 0; i<sells.size();i++){
	orderBook.getSellOrders().put(sells.getJsonObject(i).getDouble("Rate"), sells.getJsonObject(i).getDouble("Quantity"));
}
vertx.eventBus().publish(MessageDefinitions.ORDERBOOK_READY+":"+tradingPair, "ready");
    	} catch(Exception e){
    		e.printStackTrace();
    		System.out.println("Failed setting up Order Book");
    	}
    };
}
 
開發者ID:AlxGDev,項目名稱:BittrexGatherer,代碼行數:21,代碼來源:BittrexOrderBookVerticle.java

示例7: createListCharHandler

import io.vertx.core.eventbus.Message; //導入依賴的package包/類
private Handler<AsyncResult<List<Character>>> createListCharHandler(Message msg) {
  return res -> {
    if (res.failed()) {
      if (res.cause() instanceof ServiceException) {
        msg.reply(res.cause());
      } else {
        msg.reply(new ServiceException(-1, res.cause().getMessage()));
      }
    } else {
      JsonArray arr = new JsonArray();
      for (Character chr: res.result()) {
        arr.add((int) chr);
      }
      msg.reply(arr);
    }
  };
}
 
開發者ID:cescoffier,項目名稱:vertx-kubernetes-workshop,代碼行數:18,代碼來源:PortfolioServiceVertxProxyHandler.java

示例8: createHandler

import io.vertx.core.eventbus.Message; //導入依賴的package包/類
private <T> Handler<AsyncResult<T>> createHandler(Message msg) {
  return res -> {
    if (res.failed()) {
      if (res.cause() instanceof ServiceException) {
        msg.reply(res.cause());
      } else {
        msg.reply(new ServiceException(-1, res.cause().getMessage()));
      }
    } else {
      if (res.result() != null  && res.result().getClass().isEnum()) {
        msg.reply(((Enum) res.result()).name());
      } else {
        msg.reply(res.result());
      }
    }
  };
}
 
開發者ID:pflima92,項目名稱:jspare-vertx-ms-blueprint,代碼行數:18,代碼來源:MailServiceVertxProxyHandler.java

示例9: forge

import io.vertx.core.eventbus.Message; //導入依賴的package包/類
public void forge(Message<JsonObject> request) {
    JsonObject metadata = buildMetadata(request.body());
    log.info("Forging project with request: {}", metadata);
    createTempDir(metadata)
        .compose(v -> generate(metadata))
        .compose(v -> archive(metadata))
        .setHandler(ar -> {
            if (ar.failed()) {
                log.error("Impossible to create project {}: {}", metadata, ar.cause().getMessage());
                request.fail(-1, "Impossible to createProject");
            } else {
                String archivePath = ar.result();
                log.debug("Archive forged: {}", archivePath);
                metadata.put("archivePath", archivePath);
                vertx.eventBus().publish("forge:created", metadata);
                request.reply(metadata);
            }
        });
}
 
開發者ID:danielpetisme,項目名稱:vertx-forge,代碼行數:20,代碼來源:ForgeService.java

示例10: registerSynonyms

import io.vertx.core.eventbus.Message; //導入依賴的package包/類
private void registerSynonyms() {
    EventBus eventBus = vertx.eventBus();

    eventBus.consumer(WordnetAddresses.SYNONYMS.getAddress(), (Handler<Message<String>>) message -> {
        String body = message.body();

        IDictionary dictionary = dictionaryCache.getDictionary();

        IIndexWord idxWord = dictionary.getIndexWord(body, POS.NOUN);
        IWordID wordID = idxWord.getWordIDs().get(0); // 1st meaning
        IWord word = dictionary.getWord(wordID);
        ISynset synset = word.getSynset();

        List<String> synonyms = synset.getWords().stream().map(IWord::getLemma).collect(Collectors.toList());

        message.reply(new JsonArray(synonyms));
    });
}
 
開發者ID:bpark,項目名稱:chlorophytum-semantics,代碼行數:19,代碼來源:WordnetVerticle.java

示例11: fetchPage

import io.vertx.core.eventbus.Message; //導入依賴的package包/類
private void fetchPage(Message<JsonObject> message) {
  String requestedPage = message.body().getString("page");
  JsonArray params = new JsonArray().add(requestedPage);

  dbClient.queryWithParams(sqlQueries.get(SqlQuery.GET_PAGE), params, fetch -> {
    if (fetch.succeeded()) {
      JsonObject response = new JsonObject();
      ResultSet resultSet = fetch.result();
      if (resultSet.getNumRows() == 0) {
        response.put("found", false);
      } else {
        response.put("found", true);
        JsonArray row = resultSet.getResults().get(0);
        response.put("id", row.getInteger(0));
        response.put("rawContent", row.getString(1));
      }
      message.reply(response);
    } else {
      reportQueryError(message, fetch.cause());
    }
  });
}
 
開發者ID:dreamzyh,項目名稱:vertx-guide-for-java-devs_chinese,代碼行數:23,代碼來源:WikiDatabaseVerticle.java

示例12: handler

import io.vertx.core.eventbus.Message; //導入依賴的package包/類
private Handler<Message<JsonObject>> handler(ServiceHandler serviceHandler) {
	return msg -> {
		vertx.executeBlocking(ar -> {
			try {
				ar.complete(serviceHandler.invokeService(msg.body()));
			} catch (Exception e) {
				ar.fail(e);
			}
		}, res -> {
			if (res.succeeded()) {
				msg.reply(res.result());
			} else {
				int failureCode = 500;
				String message = res.cause().getMessage();
				msg.fail(failureCode, message);
			}
		});
	};
}
 
開發者ID:simonemasoni,項目名稱:vertx_spring,代碼行數:20,代碼來源:ServiceVerticle.java

示例13: starter

import io.vertx.core.eventbus.Message; //導入依賴的package包/類
public void starter(Message<JsonObject> request) {
  JsonObject metadata = buildMetadata(request.body());
  log.info("Forging project with request: {}", metadata);
  createTempDir(metadata)
    .compose(v -> generate(metadata))
    .compose(v -> archive(metadata))
    .setHandler(ar -> {
      if (ar.failed()) {
        log.error("Impossible to create project {}: {}", metadata, ar.cause().getMessage());
        request.fail(-1, "Impossible to createProject");
      } else {
        String archivePath = ar.result();
        log.debug("Archive starterd: {}", archivePath);
        metadata.put("archivePath", archivePath);
        vertx.eventBus().publish("starter:created", metadata);
        request.reply(metadata);
      }
    });
}
 
開發者ID:vert-x3,項目名稱:vertx-starter,代碼行數:20,代碼來源:StarterService.java

示例14: enrichData

import io.vertx.core.eventbus.Message; //導入依賴的package包/類
void enrichData(final Message<JsonArray> msg) {
    //array of
    /*
        [
            {target: "name", datapoints: [ [value,ts],[value,ts]] }
        ]
     */
    msg.reply(msg.body()
                 .stream()
                 .parallel()
                 .map(o -> (JsonObject) o)
                 .map(target -> new JsonObject().put("target", target.getString("target") + "_btc")
                                                .put("datapoints",
                                                     adjustByBitcoingPrice(target.getJsonArray("datapoints")))

                 )
                 .collect(toJsonArray()));
}
 
開發者ID:gmuecke,項目名稱:grafana-vertx-datasource,代碼行數:19,代碼來源:BitcoinAdjustedData.java

示例15: searchAnnotations

import io.vertx.core.eventbus.Message; //導入依賴的package包/類
/**
 * Searches for annotation in the given time range
 *
 * @param msg
 */
private void searchAnnotations(final Message<JsonObject> msg) {

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

    //get the parameter from the request
    final String from = annotation.getJsonObject("range").getString("from");
    final String to = annotation.getJsonObject("range").getString("to");
    final Range range = rangeParser.parse(from, to);
    final JsonObject an = annotation.getJsonObject("annotation");

    //build the query and find options
    final JsonObject annotationQuery = $and(obj(an.getString("query")),
                                            obj("n.begin", $gte(range.getStart())),
                                            obj("n.begin", $lte(range.getEnd())));
    final FindOptions findOptions = new FindOptions().setSort(obj("n.begin", 1)).setLimit(1);

    //query for annotations and map the result
    client.findWithOptions(collectionName, annotationQuery, findOptions, result -> {
        if (result.succeeded()) {
            msg.reply(result.result()
                            .stream()
                            .map(a -> obj().put("annotation", an)
                                           .put("time", a.getJsonObject("n").getLong("begin"))
                                           .put("title", a.getJsonObject("t").getString("name"))
                                           .put("tags", arr()))
                            .collect(toJsonArray()));
        } else {
            LOG.error("Annotation query failed", result.cause());
            msg.reply(arr());
        }
    });
}
 
開發者ID:gmuecke,項目名稱:grafana-vertx-datasource,代碼行數:39,代碼來源:AnnotationVerticle.java


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