io.vertx.core.eventbus.Message Java Examples
The following examples show how to use
io.vertx.core.eventbus.Message.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryableVertxProxyHandler.java From vertx-graphql-service-discovery with Apache License 2.0 | 6 votes |
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); } }; }
Example #2
Source File: CounterServiceVertxProxyHandler.java From vertx-blueprint-microservice with Apache License 2.0 | 6 votes |
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); } }; }
Example #3
Source File: PaymentQueryServiceVertxProxyHandler.java From vertx-blueprint-microservice with Apache License 2.0 | 6 votes |
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); } }; }
Example #4
Source File: Jukebox.java From vertx-in-action with MIT License | 6 votes |
private void list(Message<?> request) { vertx.fileSystem().readDir("tracks", ".*mp3$", ar -> { if (ar.succeeded()) { List<String> files = ar.result() .stream() .map(File::new) .map(File::getName) .collect(Collectors.toList()); JsonObject json = new JsonObject().put("files", new JsonArray(files)); request.reply(json); } else { logger.error("readDir failed", ar.cause()); request.fail(500, ar.cause().getMessage()); } }); }
Example #5
Source File: RedisMessageBroker.java From xyz-hub with Apache License 2.0 | 6 votes |
private void subscribeOwnNode(Handler<AsyncResult<Void>> callback) { logger.info("Subscribing the NODE=" + Node.OWN_INSTANCE.getUrl()); redis.subscribe(CHANNEL, ar -> { if (ar.succeeded()) { logger.info("Subscription succeeded for NODE=" + Node.OWN_INSTANCE.getUrl()); Service.vertx.eventBus().consumer("io.vertx.redis." + CHANNEL, message -> { if (message instanceof Message && message.body() instanceof JsonObject) { receiveRawMessage(((JsonObject) message.body()).getJsonObject("value").getString("message")); } }); } else if (ar.failed()) logger.error("The Node could not be subscribed as AdminMessage listener. No AdminMessages will be received by this node.", ar.cause()); }); }
Example #6
Source File: LogService.java From gushici with GNU General Public License v3.0 | 6 votes |
private void getHistoryFromRedis(Message<JsonObject> message) { Future<String> total = Future.future(f -> redisClient.hget(Key.REDIS_CLICKS_TOTAL_HASH, "total", f)); // 7天的历史点击量 LocalDate localDate = LocalDate.now(); List<String> keys = new ArrayList<>(); for (int i = 0; i < 7; i++) { keys.add(localDate.toString()); localDate = localDate.minusDays(1); } Future<JsonArray> history = Future.future(f -> redisClient.hmget(Key.REDIS_CLICKS_HISTORY_HASH, keys, f)); CompositeFuture.all(Arrays.asList(total, history)).setHandler(v -> { if (v.succeeded()) { JsonObject result = new JsonObject(); result.put("总点击量", total.result()); result.put("最近七天点击量", history.result()); message.reply(result); } else { log.error("日志获取异常", v.cause()); message.fail(500, v.cause().getMessage()); } }); }
Example #7
Source File: DataService.java From gushici with GNU General Public License v3.0 | 6 votes |
/** * @param message example: {format: "png", categories: [shenghuo, buyi]} */ private void getGushiciFromRedis(Message<JsonObject> message) { JsonArray realCategory = new JsonArray() .add("png".equals(message.body().getString("format")) ? "img" : "json") .addAll(message.body().getJsonArray("categories")); checkAndGetKey(realCategory) .compose(key -> Future.<String>future(s -> redisClient.srandmember(key, s))) // 从 set 随机返回一个对象 .setHandler(res -> { if (res.succeeded()) { message.reply(res.result()); } else { if (res.cause() instanceof ReplyException) { ReplyException exception = (ReplyException) res.cause(); message.fail(exception.failureCode(), exception.getMessage()); } else { message.fail(500, res.cause().getMessage()); } } }); }
Example #8
Source File: EventBusConsumer.java From quarkus with Apache License 2.0 | 6 votes |
/** * This method generates the following code: * {@code * Logger.getLogger(EventBusConsumer.class.getName()).warn(...); * } * It prints a deprecation method if the method annotated with {@link io.quarkus.vertx.ConsumeEvent} uses a * deprecated type. * * @param invoke the invoker * @param method the method using the deprecated type * @param deprecatedClass the deprecated type */ private static void logDeprecation(BytecodeCreator invoke, MethodInfo method, String deprecatedClass) { String msg = String .format("The `%s.%s` method is using the deprecated `%s` class. This class will be removed in a " + "future version. It is recommended to switch to `%s`", method.declaringClass().name(), method.name(), deprecatedClass, io.vertx.mutiny.core.eventbus.Message.class.getName()); ResultHandle loggerName = invoke.load(EventBusConsumer.class.getName()); ResultHandle message = invoke.load(msg); MethodDescriptor getLoggerMethod = MethodDescriptor .ofMethod(Logger.class, "getLogger", Logger.class, String.class); ResultHandle logger = invoke .invokeStaticMethod(getLoggerMethod, loggerName); MethodDescriptor warnMethod = MethodDescriptor.ofMethod(Logger.class, "warn", Void.TYPE, Object.class); invoke.invokeVirtualMethod(warnMethod, logger, message); }
Example #9
Source File: JobServiceVertxProxyHandler.java From vertx-kue with Apache License 2.0 | 6 votes |
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); } }; }
Example #10
Source File: StoreCRUDServiceVertxProxyHandler.java From vertx-blueprint-microservice with Apache License 2.0 | 6 votes |
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()); } } }; }
Example #11
Source File: OrderServiceVertxProxyHandler.java From vertx-blueprint-microservice with Apache License 2.0 | 6 votes |
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); } }; }
Example #12
Source File: VerticleHelper.java From vertx-swagger with Apache License 2.0 | 6 votes |
public void manageError(Message<JsonObject> message, Throwable cause, String serviceName) { int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); DeliveryOptions deliveryOptions = new DeliveryOptions(); if (cause instanceof MainApiException) { code = ((MainApiException)cause).getStatusCode(); statusMessage = ((MainApiException)cause).getStatusMessage(); deliveryOptions.setHeaders(((MainApiException)cause).getHeaders()); } else { logUnexpectedError(serviceName, cause); } deliveryOptions.addHeader(SwaggerRouter.CUSTOM_STATUS_CODE_HEADER_KEY, String.valueOf(code)); deliveryOptions.addHeader(SwaggerRouter.CUSTOM_STATUS_MESSAGE_HEADER_KEY, statusMessage); message.reply(null, deliveryOptions); }
Example #13
Source File: PortfolioServiceVertxProxyHandler.java From vertx-microservices-workshop with Apache License 2.0 | 6 votes |
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); } }; }
Example #14
Source File: EchoServiceVertxProxyHandler.java From weld-vertx with Apache License 2.0 | 6 votes |
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); } }; }
Example #15
Source File: EchoServiceVertxProxyHandler.java From weld-vertx with Apache License 2.0 | 6 votes |
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); } }; }
Example #16
Source File: StoreCRUDServiceVertxProxyHandler.java From vertx-blueprint-microservice with Apache License 2.0 | 6 votes |
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); } }; }
Example #17
Source File: CheckoutServiceVertxProxyHandler.java From vertx-blueprint-microservice with Apache License 2.0 | 6 votes |
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); } }; }
Example #18
Source File: PortfolioServiceVertxProxyHandler.java From vertx-microservices-workshop with Apache License 2.0 | 6 votes |
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); } }; }
Example #19
Source File: PortfolioServiceVertxProxyHandler.java From vertx-kubernetes-workshop with Apache License 2.0 | 6 votes |
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); } }; }
Example #20
Source File: PortfolioServiceVertxProxyHandler.java From vertx-kubernetes-workshop with Apache License 2.0 | 6 votes |
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()); } } }; }
Example #21
Source File: AccountServiceVertxProxyHandler.java From vertx-blueprint-microservice with Apache License 2.0 | 6 votes |
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()); } } }; }
Example #22
Source File: PortfolioServiceVertxProxyHandler.java From microtrader with MIT License | 6 votes |
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); } }; }
Example #23
Source File: VxApiApplication.java From VX-API-Gateway with MIT License | 6 votes |
/** * 更新一个路由 * * @param msg */ public void updtRoute(Message<JsonObject> msg) { if (msg.body() == null) { msg.fail(1400, "参数不能为空"); return; } VxApisDTO dto = VxApisDTO.fromJson(msg.body()); if (dto == null) { msg.fail(1405, "参数不能为空"); return; } String apiName = dto.getApiName(); if (httpRouteMaps.get(apiName) != null) { httpRouteMaps.get(apiName).forEach(r -> r.disable().remove()); } if (httpsRouteMaps.get(apiName) != null) { httpsRouteMaps.get(apiName).forEach(r -> r.disable().remove()); } addRoute(msg); }
Example #24
Source File: DeploymentVerticle.java From VX-API-Gateway with MIT License | 6 votes |
/** * 启动API的服务,该服务为递归会阻塞线程,请在executeBlocking中执行,startResult参数传入null * * @param body * 引用信息 * @param appName * 应用的名称 * @param elseRouteToThis * 是否代理启动 * @param serverType * 服务类型1=HTTP服务,2=HTTPS服务,3=webSocket服务 * @param handler * 返回结果 * @param startResult * 启动的结果,调用时需要传入null */ public void startApiService(JsonObject body, String appName, Boolean elseRouteToThis, Integer serverType, Handler<AsyncResult<Message<Integer>>> handler, AsyncResult<Message<Integer>> startResult) { if (startResult != null) { handler.handle(startResult); return; } String address = thisVertxName + appName + VxApiEventBusAddressConstant.APPLICATION_ADD_API_SUFFIX; JsonObject params = new JsonObject(); params.put("api", body); if (elseRouteToThis != null) { params.put("elseRouteToThis", elseRouteToThis); } if (serverType != null) { params.put("serverType", serverType); } vertx.eventBus().<Integer>send(address, params, res -> { startApiService(null, null, null, null, handler, res); }); }
Example #25
Source File: CLIVerticle.java From VX-API-Gateway with MIT License | 5 votes |
/** * 启动所有网关应用 * * @param msg */ public void startAllAPP(Message<JsonObject> msg) { LOG.info("cli->执行启动所有网关应用..."); vertx.executeBlocking(futrue -> { vertx.eventBus().<JsonArray>send(thisVertxName + VxApiEventBusAddressConstant.FIND_APP, null, reply -> { if (reply.succeeded()) { JsonArray body = reply.result().body(); if (body != null && body.size() > 0) { startAppService(body, 0, 0, false, handler -> { Integer success = handler.result().getInteger("success", 0); Integer fail = handler.result().getInteger("fail", 0); LOG.info("cli->执行启动所有网关应用-->结果:成功数量:" + success + ",失败数量:" + fail); futrue.complete(); }); } else { LOG.info("cli->执行启动所有网关应用-->结果:网关应用数量为:0"); futrue.complete(); } } else { LOG.error("cli->执行启动所有网关应用-->失败:" + reply.cause()); futrue.fail(reply.cause()); } }); }, result -> { if (result.succeeded()) { msg.reply("ok"); } else { msg.reply("500"); LOG.error("cli->执行启动所有网关应用-->失败:" + result.cause()); } }); }
Example #26
Source File: SysVerticle.java From VX-API-Gateway with MIT License | 5 votes |
/** * 查看API运行信息 * * @param msg */ public void getTrackInfo(Message<JsonObject> msg) { String appName = msg.body().getString("appName"); String apiName = msg.body().getString("apiName"); String key = appName + "-" + apiName; JsonObject result = new JsonObject(); result.put("rc", requstCount.get(key) == null ? 0L : requstCount.get(key)); result.put("ec", requstFailedCount.get(key) == null ? 0L : requstFailedCount.get(key)); result.put("track", trackSucceededMap.get(key) == null ? new JsonObject() : trackSucceededMap.get(key)); msg.reply(result); }
Example #27
Source File: CLIVerticle.java From VX-API-Gateway with MIT License | 5 votes |
/** * 启动所有网关应用与API * * @param msg */ public void startEverything(Message<JsonObject> msg) { LOG.info("cli->执行启动所有网关应用与API..."); vertx.executeBlocking(futrue -> { vertx.eventBus().<JsonArray>send(thisVertxName + VxApiEventBusAddressConstant.FIND_APP, null, reply -> { if (reply.succeeded()) { JsonArray body = reply.result().body(); if (body != null && body.size() > 0) { startAppService(body, 0, 0, true, handler -> { Integer success = handler.result().getInteger("success", 0); Integer fail = handler.result().getInteger("fail", 0); LOG.info("cli->执行启动所有网关应用与API-->结果:成功数量:" + success + ",失败数量:" + fail); futrue.complete(); }); } else { LOG.info("cli->执行启动所有网关应用与API-->结果:网关应用数量为:0"); futrue.complete(); } } else { LOG.error("cli->执行启动所有网关应用与API-->失败:" + reply.cause()); futrue.fail(reply.cause()); } }); }, result -> { if (result.succeeded()) { msg.reply("ok"); } else { msg.reply("500"); LOG.error("cli->执行启动所有网关应用与API-->失败:" + result.cause()); } }); }
Example #28
Source File: QueryableVertxProxyHandler.java From vertx-graphql-service-discovery with Apache License 2.0 | 5 votes |
private <T> Handler<AsyncResult<List<T>>> createListHandler(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 { msg.reply(new JsonArray(res.result())); } }; }
Example #29
Source File: CheckoutServiceVertxProxyHandler.java From vertx-blueprint-microservice with Apache License 2.0 | 5 votes |
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 "checkout": { service.checkout((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; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.reply(new ServiceException(500, t.getMessage())); throw t; } }
Example #30
Source File: CounterServiceVertxProxyHandler.java From vertx-blueprint-microservice with Apache License 2.0 | 5 votes |
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 "addThenRetrieve": { service.addThenRetrieve((java.lang.String)json.getValue("key"), createHandler(msg)); break; } case "addThenRetrieveBy": { service.addThenRetrieveBy((java.lang.String)json.getValue("key"), json.getValue("increment") == null ? null : (json.getLong("increment").longValue()), createHandler(msg)); break; } case "retrieveThenAdd": { service.retrieveThenAdd((java.lang.String)json.getValue("key"), createHandler(msg)); break; } case "reset": { service.reset((java.lang.String)json.getValue("key"), createHandler(msg)); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.reply(new ServiceException(500, t.getMessage())); throw t; } }