Java 类io.vertx.core.eventbus.DeliveryOptions 实例源码

项目:vertx-sfdc-platformevents    文件:CometD.java   
protected void processOneResult(final JsonObject dataChange) {

        final JsonObject data = dataChange.getJsonObject("data");
        final JsonObject payload = data.getJsonObject("payload");
        // We send it off to the eventbus and in any case have the
        // final destination header set - just in case
        final EventBus eb = this.getVertx().eventBus();
        final DeliveryOptions opts = new DeliveryOptions();
        this.getListenerConfig().getEventBusAddresses().forEach(destination -> {
            opts.addHeader(Constants.BUS_FINAL_DESTINATION, destination);
        });

        // Intermediate step for deduplication of messages
        if (this.useDedupService()) {
            eb.publish(this.getListenerConfig().getEventBusDedupAddress(), payload, opts);
        } else {
            this.getListenerConfig().getEventBusAddresses().forEach(destination -> {
                try {
                    eb.publish(destination, payload, opts);
                    this.logger.info("Sending to [" + destination + "]:" + payload.toString());
                } catch (final Throwable t) {
                    this.logger.error(t.getMessage(), t);
                }
            });
        }
    }
项目:vertx-guide-for-java-devs    文件:HttpServerVerticle.java   
private void indexHandler(RoutingContext context) {

    DeliveryOptions options = new DeliveryOptions().addHeader("action", "all-pages"); // <2>

    vertx.eventBus().send(wikiDbQueue, new JsonObject(), options, reply -> {  // <1>
      if (reply.succeeded()) {
        JsonObject body = (JsonObject) reply.result().body();   // <3>
        context.put("title", "Wiki home");
        context.put("pages", body.getJsonArray("pages").getList());
        templateEngine.render(context, "templates", "/index.ftl", ar -> {
          if (ar.succeeded()) {
            context.response().putHeader("Content-Type", "text/html");
            context.response().end(ar.result());
          } else {
            context.fail(ar.cause());
          }
        });
      } else {
        context.fail(reply.cause());
      }
    });
  }
项目:ethereum-ingest    文件:BlockService.java   
private Future<Void> importTx(StorableBlock block, JsonObject transactions) {
    Future<Void> future = Future.future();
    DeliveryOptions delivery = new DeliveryOptions().setSendTimeout(ONE_MINUTE);

    if (config.isTxImport()) {
        context.bus().send(TX_ADDR, transactions, delivery, done -> {
            listener.onImported(block.getHash(), block.getNumber());
            if (done.succeeded()) {
                Throwable result = (Throwable) done.result().body();
                if (result == null) {
                    future.complete();
                } else {
                    future.fail(result);
                }
            } else {
                future.fail(done.cause());
            }
        });
    } else {
        future.complete();
    }
    return future;
}
项目:vertx-guide-for-java-devs_chinese    文件:HttpServerVerticle.java   
private void indexHandler(RoutingContext context) {

    DeliveryOptions options = new DeliveryOptions().addHeader("action", "all-pages"); // <2>

    vertx.eventBus().send(wikiDbQueue, new JsonObject(), options, reply -> {  // <1>
      if (reply.succeeded()) {
        JsonObject body = (JsonObject) reply.result().body();   // <3>
        context.put("title", "Wiki home");
        context.put("pages", body.getJsonArray("pages").getList());
        templateEngine.render(context, "templates", "/index.ftl", ar -> {
          if (ar.succeeded()) {
            context.response().putHeader("Content-Type", "text/html");
            context.response().end(ar.result());
          } else {
            context.fail(ar.cause());
          }
        });
      } else {
        context.fail(reply.cause());
      }
    });
  }
项目:vertx-kubernetes-workshop    文件:PortfolioServiceVertxEBProxy.java   
public void getPortfolio(Handler<AsyncResult<Portfolio>> resultHandler) {
  if (closed) {
  resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return;
  }
  JsonObject _json = new JsonObject();
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "getPortfolio");
  _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      resultHandler.handle(Future.failedFuture(res.cause()));
    } else {
      resultHandler.handle(Future.succeededFuture(res.result().body() == null ? null : new Portfolio(res.result().body())));
                    }
  });
}
项目:vertx-kubernetes-workshop    文件:PortfolioServiceVertxEBProxy.java   
public void buy(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) {
  if (closed) {
  resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return;
  }
  JsonObject _json = new JsonObject();
  _json.put("amount", amount);
  _json.put("quote", quote);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "buy");
  _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      resultHandler.handle(Future.failedFuture(res.cause()));
    } else {
      resultHandler.handle(Future.succeededFuture(res.result().body() == null ? null : new Portfolio(res.result().body())));
                    }
  });
}
项目:vertx-kubernetes-workshop    文件:PortfolioServiceVertxEBProxy.java   
public void sell(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) {
  if (closed) {
  resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return;
  }
  JsonObject _json = new JsonObject();
  _json.put("amount", amount);
  _json.put("quote", quote);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "sell");
  _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      resultHandler.handle(Future.failedFuture(res.cause()));
    } else {
      resultHandler.handle(Future.succeededFuture(res.result().body() == null ? null : new Portfolio(res.result().body())));
                    }
  });
}
项目:vertx-kubernetes-workshop    文件:PortfolioServiceVertxEBProxy.java   
public void evaluate(Handler<AsyncResult<Double>> resultHandler) {
  if (closed) {
  resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return;
  }
  JsonObject _json = new JsonObject();
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "evaluate");
  _vertx.eventBus().<Double>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      resultHandler.handle(Future.failedFuture(res.cause()));
    } else {
      resultHandler.handle(Future.succeededFuture(res.result().body()));
    }
  });
}
项目:jspare-vertx-ms-blueprint    文件:NotificationServiceVertxEBProxy.java   
public NotificationService createNotification(Handler<AsyncResult<JsonObject>> resultHandler) {
  if (closed) {
    resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "createNotification");
  _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      resultHandler.handle(Future.failedFuture(res.cause()));
    } else {
      resultHandler.handle(Future.succeededFuture(res.result().body()));
    }
  });
  return this;
}
项目:jspare-vertx-ms-blueprint    文件:MailServiceVertxEBProxy.java   
public MailService send(MailMessage message, Handler<AsyncResult<MailResult>> resultHandler) {
  if (closed) {
    resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("message", message == null ? null : message.toJson());
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "send");
  _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      resultHandler.handle(Future.failedFuture(res.cause()));
    } else {
      resultHandler.handle(Future.succeededFuture(res.result().body() == null ? null : new MailResult(res.result().body())));
                    }
  });
  return this;
}
项目:jspare-vertx-ms-blueprint    文件:ConfigurationProviderVertxEBProxy.java   
public ConfigurationProvider getConfiguration(String name, Handler<AsyncResult<JsonObject>> resultHandler) {
  if (closed) {
    resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("name", name);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "getConfiguration");
  _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      resultHandler.handle(Future.failedFuture(res.cause()));
    } else {
      resultHandler.handle(Future.succeededFuture(res.result().body()));
    }
  });
  return this;
}
项目:vertx-process-manager    文件:ProcessServiceVertxEBProxy.java   
public ProcessService startProcessWithVariables(String processId, JsonObject jsonObject, Handler<AsyncResult<ProcessInstanceService>> handler) {
  if (closed) {
    handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("processId", processId);
  _json.put("jsonObject", jsonObject);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "startProcessWithVariables");
  _vertx.eventBus().<ProcessInstanceService>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      handler.handle(Future.failedFuture(res.cause()));
    } else {
      String addr = res.result().headers().get("proxyaddr");
      handler.handle(Future.succeededFuture(ProxyHelper.createProxy(ProcessInstanceService.class, _vertx, addr)));
    }
  });
  return this;
}
项目:vertx-camel-bridge    文件:OutboundEndpointTest.java   
@Test
public void testWithMockWithASingleMessageHeadersNotCopied() throws Exception {
  MockEndpoint endpoint = (MockEndpoint) camel.getComponent("mock").createEndpoint("mock:foo");
  camel.addEndpoint("output", endpoint);

  bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel)
      .addOutboundMapping(fromVertx("test").toCamel("output").withoutHeadersCopy()));

  camel.start();
  BridgeHelper.startBlocking(bridge);

  vertx.eventBus().send("test", "hello", new DeliveryOptions().addHeader("key", "value"));

  await().atMost(DEFAULT_TIMEOUT).until(() -> !endpoint.getExchanges().isEmpty());
  endpoint.expectedBodiesReceived("hello");

  Exchange exchange = endpoint.getExchanges().get(0);
  assertThat(exchange.getIn().getBody()).isEqualTo("hello");
  assertThat(exchange.getIn().getHeaders()).doesNotContainKey("key");
}
项目:vertx-camel-bridge    文件:CamelHelperTest.java   
@Test
public void testTheCopyOfHeaders() {
  Message msg = new DefaultMessage();
  msg.setHeader("CamelRedelivered", false);
  msg.setHeader("CamelRedeliveryCounter", 0);
  msg.setHeader("JMSCorrelationID", "");
  msg.setHeader("JMSDestination", "queue://dev.msy.queue.log.fwd");
  msg.setHeader("JMSReplyTo", null);

  DeliveryOptions options = CamelHelper.getDeliveryOptions(msg, true);

  assertThat(options.getHeaders().get("CamelRedelivered")).isEqualToIgnoringCase("false");
  assertThat(options.getHeaders().get("CamelRedeliveryCounter")).isEqualToIgnoringCase("0");
  assertThat(options.getHeaders().get("JMSCorrelationID")).isEqualToIgnoringCase("");
  assertThat(options.getHeaders().get("JMSDestination")).isEqualToIgnoringCase("queue://dev.msy.queue.log.fwd");
  assertThat(options.getHeaders().get("JMSReplyTo")).isNull();

}
项目:Elastic-Components    文件:FlowToMessageHandlerConverterImpl.java   
@Override
public MessageHandler<T> convert(Flow flow) {

    return message -> {

        try {

            flow.<Msg>start(
                Msg.<T>builder()
                    .context(new ContextImpl(ImmutableMap.of()))
                    .headers(new HeadersImpl(
                        ComposerUtils.toListMultimap(message.headers()),
                        convertersMap.getMap()
                    ))
                    .userId(userIdConverter.convert(message.headers().get(UserModel.userId)))
                    .body(message.body())
                    .build())
                .then(msg -> message.reply(msg.body(), new DeliveryOptions().setHeaders(new VertxMultiMap(msg.headers().getMultimap()))))
                .err(throwable -> messageProcessingErrorHandler.handleError(throwable, message));

        } catch (Exception ex) {

            messageProcessingErrorHandler.handleError(ex, message);
        }
    };
}
项目:Elastic-Components    文件:BroadcastStateHandlerImpl.java   
@Override
public Promise<StateTrigger<Msg<Object>>> handle(Msg<Object> msg) throws Throwable {
    messageBus.publish(
        MessageBus.Params.builder()
            .address(eventAddress)
            .message(msg.body())
            .options(
                new DeliveryOptions()
                    .setHeaders(
                        ComposerUtils.toVertxMultimap(msg.headers().getMultimap())
                    )
            )
            .build()
    );

    return Promises.of(
        Flow.trigger(Events.next, msg)
    );
}
项目:Elastic-Components    文件:BroadcastAllStateHandlerImpl.java   
@Override
public Promise<StateTrigger<Msg<JsonArray>>> handle(Msg<JsonArray> msg) throws Throwable {
    msg.body().forEach(
        obj -> messageBus.publish(
            MessageBus.Params.builder()
                .address(eventAddress)
                .message(obj)
                .options(
                    new DeliveryOptions()
                        .setHeaders(
                            ComposerUtils.toVertxMultimap(msg.headers().getMultimap())
                        )
                )
                .build()
        )
    );

    return Promises.of(
        Flow.trigger(Events.next, msg)
    );
}
项目:vertx-process-manager    文件:RuleServiceVertxEBProxy.java   
public RuleService insert(String packageName, String typeName, JsonObject attributes, Handler<AsyncResult<String>> handler) {
  if (closed) {
    handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("packageName", packageName);
  _json.put("typeName", typeName);
  _json.put("attributes", attributes);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "insert");
  _vertx.eventBus().<String>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      handler.handle(Future.failedFuture(res.cause()));
    } else {
      handler.handle(Future.succeededFuture(res.result().body()));
    }
  });
  return this;
}
项目:vertx-process-manager    文件:ProcessInstanceServiceVertxEBProxy.java   
public ProcessInstanceService getInstanceId(Handler<AsyncResult<Long>> handler) {
  if (closed) {
    handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "getInstanceId");
  _vertx.eventBus().<Long>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      handler.handle(Future.failedFuture(res.cause()));
    } else {
      handler.handle(Future.succeededFuture(res.result().body()));
    }
  });
  return this;
}
项目:vertx-process-manager    文件:ProcessInstanceServiceVertxEBProxy.java   
public ProcessInstanceService getState(Handler<AsyncResult<ProcessState>> handler) {
  if (closed) {
    handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "getState");
  _vertx.eventBus().<String>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      handler.handle(Future.failedFuture(res.cause()));
    } else {
      handler.handle(Future.succeededFuture(res.result().body() == null ? null : ProcessState.valueOf(res.result().body())));
    }
  });
  return this;
}
项目:direwolves    文件:EventbusRpcHandler.java   
private DeliveryOptions createDeliveryOptions(EventbusRpcRequest request) {
    DeliveryOptions deliveryOptions = new DeliveryOptions()
            .addHeader("x-request-id", request.id())
            .addHeader("x-request-policy", request.policy())
            .addHeader("x-request-address", request.address());
//    if (!Strings.isNullOrEmpty(request.action())) {
//      deliveryOptions.addHeader("action", request.action());
//    }
    Multimap<String, String> headers = request.headers();
    for (String key : headers.keySet()) {
      for (String value : headers.get(key)) {
        deliveryOptions.addHeader(key, value);
      }
    }
    return deliveryOptions;
  }
项目:vertx-microservices-workshop    文件:PortfolioServiceVertxEBProxy.java   
public void getPortfolio(Handler<AsyncResult<Portfolio>> resultHandler) {
  if (closed) {
    resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return;
  }
  JsonObject _json = new JsonObject();
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "getPortfolio");
  _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      resultHandler.handle(Future.failedFuture(res.cause()));
    } else {
      resultHandler.handle(Future.succeededFuture(res.result().body() == null ? null : new Portfolio(res.result().body())));
                    }
  });
}
项目:knotx    文件:ServiceKnotConfiguration.java   
public ServiceKnotConfiguration(JsonObject config) {
  address = config.getString("address");
  services = config.getJsonArray("services").stream()
      .map(item -> (JsonObject) item)
      .map(item -> {
        ServiceMetadata metadata = new ServiceMetadata();
        metadata.name = item.getString("name");
        metadata.address = item.getString("address");
        metadata.params = item.getJsonObject("params");
        metadata.cacheKey = item.getString("cacheKey");
        return metadata;
      }).collect(Collectors.toList());
  deliveryOptions =
      config.containsKey("deliveryOptions") ? new DeliveryOptions(config.getJsonObject("deliveryOptions"))
          : new DeliveryOptions();
}
项目:vertx-process-manager    文件:KnowledgeServiceVertxEBProxy.java   
public KnowledgeService addClassPathResource(String resourceName, Handler<AsyncResult<Void>> handler) {
  if (closed) {
    handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("resourceName", resourceName);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "addClassPathResource");
  _vertx.eventBus().<Void>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      handler.handle(Future.failedFuture(res.cause()));
    } else {
      handler.handle(Future.succeededFuture(res.result().body()));
    }
  });
  return this;
}
项目:knotx    文件:KnotxServerConfiguration.java   
public KnotxServerConfiguration(JsonObject config) {
  displayExceptionDetails = config.getBoolean("displayExceptionDetails", false);

  customResponseHeader = config
      .getJsonObject("customResponseHeader", new JsonObject());

  allowedResponseHeaders = config.getJsonArray("allowedResponseHeaders").stream()
      .map(item -> ((String) item).toLowerCase())
      .collect(Collectors.toSet());

  defaultFlow = new KnotxFlowConfiguration(config.getJsonObject("defaultFlow"));
  customFlow = new KnotxFlowConfiguration(config.getJsonObject("customFlow"));
  fileUploadDirectory = config
      .getString("fileUploadDirectory", BodyHandler.DEFAULT_UPLOADS_DIRECTORY);
  fileUploadLimit = config.getLong("fileUploadLimit", DEFAULT_UPLOAD_LIMIT);
  serverOptions = config.getJsonObject("serverOptions", new JsonObject());
  deliveryOptions =
      config.containsKey("deliveryOptions") ? new DeliveryOptions(
          config.getJsonObject("deliveryOptions"))
          : new DeliveryOptions();
  csrfConfig = new KnotxCSRFConfig(config.getJsonObject("csrf", new JsonObject()));
}
项目:microtrader    文件:PortfolioServiceVertxEBProxy.java   
public void getPortfolio(Handler<AsyncResult<Portfolio>> resultHandler) {
  if (closed) {
  resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return;
  }
  JsonObject _json = new JsonObject();
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "getPortfolio");
  _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      resultHandler.handle(Future.failedFuture(res.cause()));
    } else {
      resultHandler.handle(Future.succeededFuture(res.result().body() == null ? null : new Portfolio(res.result().body())));
                    }
  });
}
项目:microtrader    文件:PortfolioServiceVertxEBProxy.java   
public void sell(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) {
  if (closed) {
  resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return;
  }
  JsonObject _json = new JsonObject();
  _json.put("amount", amount);
  _json.put("quote", quote);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "sell");
  _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      resultHandler.handle(Future.failedFuture(res.cause()));
    } else {
      resultHandler.handle(Future.succeededFuture(res.result().body() == null ? null : new Portfolio(res.result().body())));
                    }
  });
}
项目:microtrader    文件:PortfolioServiceVertxEBProxy.java   
public void evaluate(Handler<AsyncResult<Double>> resultHandler) {
  if (closed) {
  resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return;
  }
  JsonObject _json = new JsonObject();
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "evaluate");
  _vertx.eventBus().<Double>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      resultHandler.handle(Future.failedFuture(res.cause()));
    } else {
      resultHandler.handle(Future.succeededFuture(res.result().body()));
    }
  });
}
项目:vertx-process-manager    文件:TaskServiceVertxEBProxy.java   
public TaskService suspend(Long taskId, String userId, Handler<AsyncResult<Void>> handler) {
  if (closed) {
    handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("taskId", taskId);
  _json.put("userId", userId);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "suspend");
  _vertx.eventBus().<Void>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      handler.handle(Future.failedFuture(res.cause()));
    } else {
      handler.handle(Future.succeededFuture(res.result().body()));
    }
  });
  return this;
}
项目:vertx-process-manager    文件:ProcessServiceVertxEBProxy.java   
public ProcessService startProcess(String processId, Handler<AsyncResult<ProcessInstanceService>> handler) {
  if (closed) {
    handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("processId", processId);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "startProcess");
  _vertx.eventBus().<ProcessInstanceService>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      handler.handle(Future.failedFuture(res.cause()));
    } else {
      String addr = res.result().headers().get("proxyaddr");
      handler.handle(Future.succeededFuture(ProxyHelper.createProxy(ProcessInstanceService.class, _vertx, addr)));
    }
  });
  return this;
}
项目:vertx-swagger    文件:VerticleHelper.java   
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);
}
项目:vertx-microservices-workshop    文件:PortfolioServiceVertxEBProxy.java   
public void evaluate(Handler<AsyncResult<Double>> resultHandler) {
  if (closed) {
    resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return;
  }
  JsonObject _json = new JsonObject();
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "evaluate");
  _vertx.eventBus().<Double>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      resultHandler.handle(Future.failedFuture(res.cause()));
    } else {
      resultHandler.handle(Future.succeededFuture(res.result().body()));
    }
  });
}
项目:vertx-swagger    文件:VerticleHelper.java   
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);
}
项目:vertx-swagger    文件:VerticleHelper.java   
public <T> Handler<AsyncResult<ResourceResponse<T>>> getAsyncResultHandler(Message<JsonObject> message, String serviceName, boolean withJsonEncode, TypeReference<T> type) {
    return result -> {
        if (result.succeeded()) {
            DeliveryOptions deliveryOptions = new DeliveryOptions();
            deliveryOptions.setHeaders(result.result().getHeaders());
            if(withJsonEncode) {
                message.reply(result.result().toJson(), deliveryOptions);
            } else {
                message.reply(result.result().getResponse(), deliveryOptions);
            }
        } else {
            Throwable cause = result.cause();
            manageError(message, cause, serviceName);
        }
    };
}
项目:vertx-process-manager    文件:TaskServiceVertxEBProxy.java   
public TaskService addComment(Long taskId, String userId, String comment, Handler<AsyncResult<Void>> handler) {
  if (closed) {
    handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("taskId", taskId);
  _json.put("userId", userId);
  _json.put("comment", comment);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "addComment");
  _vertx.eventBus().<Void>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      handler.handle(Future.failedFuture(res.cause()));
    } else {
      handler.handle(Future.succeededFuture(res.result().body()));
    }
  });
  return this;
}
项目:hono    文件:HonoSaslAuthenticatorFactory.java   
@Override
public void authenticate(final JsonObject authRequest, final Handler<AsyncResult<HonoUser>> authenticationResultHandler) {

    final DeliveryOptions options = new DeliveryOptions().setSendTimeout(AUTH_REQUEST_TIMEOUT_MILLIS);
    vertx.eventBus().send(AuthenticationConstants.EVENT_BUS_ADDRESS_AUTHENTICATION_IN, authRequest, options, reply -> {
        if (reply.succeeded()) {
            JsonObject result = (JsonObject) reply.result().body();
            String token = result.getString(AuthenticationConstants.FIELD_TOKEN);
            log.debug("received token [length: {}] in response to authentication request", token.length());
            try {
                Jws<Claims> expandedToken = tokenValidator.expand(result.getString(AuthenticationConstants.FIELD_TOKEN));
                authenticationResultHandler.handle(Future.succeededFuture(new HonoUserImpl(expandedToken, token)));
            } catch (JwtException e) {
                authenticationResultHandler.handle(Future.failedFuture(e));
            }
        } else {
            authenticationResultHandler.handle(Future.failedFuture(reply.cause()));
        }
    });

}
项目:vertx-microservices-workshop    文件:PortfolioServiceVertxEBProxy.java   
public void buy(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) {
  if (closed) {
    resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return;
  }
  JsonObject _json = new JsonObject();
  _json.put("amount", amount);
  _json.put("quote", quote);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "buy");
  _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      resultHandler.handle(Future.failedFuture(res.cause()));
    } else {
      resultHandler.handle(Future.succeededFuture(res.result().body() == null ? null : new Portfolio(res.result().body())));
                    }
  });
}
项目:vertx-blueprint-microservice    文件:CheckoutServiceVertxEBProxy.java   
public void checkout(String userId, Handler<AsyncResult<CheckoutResult>> handler) {
  if (closed) {
    handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return;
  }
  JsonObject _json = new JsonObject();
  _json.put("userId", userId);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "checkout");
  _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      handler.handle(Future.failedFuture(res.cause()));
    } else {
      handler.handle(Future.succeededFuture(res.result().body() == null ? null : new CheckoutResult(res.result().body())));
                    }
  });
}
项目:vertx-blueprint-microservice    文件:PaymentQueryServiceVertxEBProxy.java   
public void addPaymentRecord(Payment payment, Handler<AsyncResult<Void>> resultHandler) {
  if (closed) {
    resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return;
  }
  JsonObject _json = new JsonObject();
  _json.put("payment", payment == null ? null : payment.toJson());
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "addPaymentRecord");
  _vertx.eventBus().<Void>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      resultHandler.handle(Future.failedFuture(res.cause()));
    } else {
      resultHandler.handle(Future.succeededFuture(res.result().body()));
    }
  });
}
项目:vertx-blueprint-microservice    文件:CounterServiceVertxEBProxy.java   
public void addThenRetrieve(String key, Handler<AsyncResult<Long>> resultHandler) {
  if (closed) {
    resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return;
  }
  JsonObject _json = new JsonObject();
  _json.put("key", key);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "addThenRetrieve");
  _vertx.eventBus().<Long>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      resultHandler.handle(Future.failedFuture(res.cause()));
    } else {
      resultHandler.handle(Future.succeededFuture(res.result().body()));
    }
  });
}