io.vertx.core.eventbus.DeliveryOptions Java Examples

The following examples show how to use io.vertx.core.eventbus.DeliveryOptions. 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: EventBusBridgeTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatEventBusMessagesContainingNoBodyAreTransferredToStomp() {
  AtomicReference<Frame> reference = new AtomicReference<>();

  clients.add(StompClient.create(vertx).connect(ar -> {
        final StompClientConnection connection = ar.result();
        connection.subscribe("/bus", reference::set,
            f -> {
              vertx.eventBus().publish("/bus", null,
                  new DeliveryOptions().addHeader("foo", "bar"));
            }
        );
      }
  ));

  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> reference.get() != null);

  assertThat(reference.get().getHeaders().get("foo")).isEqualTo("bar");
  assertThat(reference.get().getHeaders().get("destination")).isEqualTo("/bus");
  byte[] body = reference.get().getBody().getBytes();
  assertThat(body).hasSize(0);
}
 
Example #2
Source File: ProductServiceVertxEBProxy.java    From vertx-blueprint-microservice with Apache License 2.0 6 votes vote down vote up
public ProductService retrieveProductPrice(String productId, Handler<AsyncResult<JsonObject>> resultHandler) {
  if (closed) {
    resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("productId", productId);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "retrieveProductPrice");
  _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;
}
 
Example #3
Source File: StoreCRUDServiceVertxEBProxy.java    From vertx-blueprint-microservice with Apache License 2.0 6 votes vote down vote up
public void retrieveStore(String sellerId, Handler<AsyncResult<Store>> resultHandler) {
  if (closed) {
    resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return;
  }
  JsonObject _json = new JsonObject();
  _json.put("sellerId", sellerId);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "retrieveStore");
  _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 Store(res.result().body())));
                    }
  });
}
 
Example #4
Source File: OrderServiceVertxEBProxy.java    From vertx-blueprint-microservice with Apache License 2.0 6 votes vote down vote up
public OrderService initializePersistence(Handler<AsyncResult<Void>> 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", "initializePersistence");
  _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()));
    }
  });
  return this;
}
 
Example #5
Source File: SensorDataServiceVertxEBProxy.java    From vertx-in-action with MIT License 6 votes vote down vote up
@Override
public void average(Handler<AsyncResult<JsonObject>> handler){
  if (closed) {
    handler.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", "average");
  _vertx.eventBus().<JsonObject>request(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      handler.handle(Future.failedFuture(res.cause()));
    } else {
      handler.handle(Future.succeededFuture(res.result().body()));
    }
  });
}
 
Example #6
Source File: PortfolioServiceVertxEBProxy.java    From microtrader with MIT License 6 votes vote down vote up
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())));
                    }
  });
}
 
Example #7
Source File: AccountServiceVertxEBProxy.java    From vertx-blueprint-microservice with Apache License 2.0 6 votes vote down vote up
public AccountService retrieveByUsername(String username, Handler<AsyncResult<Account>> resultHandler) {
  if (closed) {
    resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("username", username);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "retrieveByUsername");
  _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 Account(res.result().body())));
                    }
  });
  return this;
}
 
Example #8
Source File: PortfolioServiceVertxEBProxy.java    From microtrader with MIT License 6 votes vote down vote up
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()));
    }
  });
}
 
Example #9
Source File: ExecuteEventbusByte.java    From vxms with Apache License 2.0 6 votes vote down vote up
/**
 * Execute the reply chain with given http status code
 *
 * @param deliveryOptions, the event b us deliver serverOptions
 */
public void execute(DeliveryOptions deliveryOptions) {
  Objects.requireNonNull(deliveryOptions);
  new ExecuteEventbusByte(
          methodId,
          vxmsShared,
          failure,
          errorMethodHandler,
          message,
          chain,
          byteConsumer,
          excecuteEventBusAndReply,
          errorHandler,
          onFailureRespond,
          deliveryOptions,
          retryCount,
          timeout,
          circuitBreakerTimeout)
      .execute();
}
 
Example #10
Source File: AccountServiceVertxEBProxy.java    From vertx-blueprint-microservice with Apache License 2.0 6 votes vote down vote up
public AccountService retrieveAllAccounts(Handler<AsyncResult<List<Account>>> 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", "retrieveAllAccounts");
  _vertx.eventBus().<JsonArray>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      resultHandler.handle(Future.failedFuture(res.cause()));
    } else {
      resultHandler.handle(Future.succeededFuture(res.result().body().stream().map(o -> o instanceof Map ? new Account(new JsonObject((Map) o)) : new Account((JsonObject) o)).collect(Collectors.toList())));
    }
  });
  return this;
}
 
Example #11
Source File: VerticleHelper.java    From vertx-swagger with Apache License 2.0 6 votes vote down vote up
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 #12
Source File: EventbusBridgeRequest.java    From vxms with Apache License 2.0 6 votes vote down vote up
/**
 * Send message and redirect the event bus response directly to the initial request
 *
 * @param id the target id to send to
 * @param message the message to send
 * @param requestOptions the delivery serverOptions for the event bus request
 */
public void sendAndRespondRequest(String id, Object message, DeliveryOptions requestOptions) {
  final Vertx vertx = vxmsShared.getVertx();
  vertx
      .eventBus()
      .send(
          id,
          message,
          requestOptions != null ? requestOptions : new DeliveryOptions(),
          event -> {
            if (event.failed()) {
              requestmessage.fail(
                  HttpResponseStatus.SERVICE_UNAVAILABLE.code(), event.cause().getMessage());
            }
            Optional.ofNullable(event.result())
                .ifPresent(
                    result ->
                        Optional.ofNullable(result.body())
                            .ifPresent(resp -> respond(resp, requestOptions)));
          });
}
 
Example #13
Source File: VerticleHelper.java    From vertx-swagger with Apache License 2.0 6 votes vote down vote up
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);
        }
    };
}
 
Example #14
Source File: VerticleHelper.java    From vertx-swagger with Apache License 2.0 6 votes vote down vote up
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 #15
Source File: EventbusBridgeResponse.java    From vxms with Apache License 2.0 6 votes vote down vote up
/**
 * Pass all parameters to execute the chain
 *
 * @param methodId the method identifier
 * @param requestmessage the message to responde
 * @param vxmsShared the vxmsShared instance, containing the Vertx instance and other shared
 *     objects per instance
 * @param failure the last failure
 * @param errorMethodHandler the error-method handler
 * @param targetId the event-bus message target-targetId
 * @param message the event-bus message
 * @param options the event-bus delivery serverOptions
 */
public EventbusBridgeResponse(
    String methodId,
    Message<Object> requestmessage,
    VxmsShared vxmsShared,
    Throwable failure,
    Consumer<Throwable> errorMethodHandler,
    String targetId,
    Object message,
    DeliveryOptions options) {
  this.methodId = methodId;
  this.vxmsShared = vxmsShared;
  this.t = failure;
  this.errorMethodHandler = errorMethodHandler;
  this.requestmessage = requestmessage;
  this.targetId = targetId;
  this.message = message;
  this.options = options;
}
 
Example #16
Source File: VerticleHelper.java    From vertx-swagger with Apache License 2.0 6 votes vote down vote up
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(Json.encode(result.result().getResponse()), deliveryOptions);
            } else {
                message.reply(result.result().getResponse(), deliveryOptions);
            }
        } else {
            Throwable cause = result.cause();
            manageError(message, cause, serviceName);
        }
    };
}
 
Example #17
Source File: AccountServiceVertxEBProxy.java    From vertx-blueprint-microservice with Apache License 2.0 6 votes vote down vote up
public AccountService retrieveAccount(String id, Handler<AsyncResult<Account>> resultHandler) {
  if (closed) {
    resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("id", id);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "retrieveAccount");
  _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 Account(res.result().body())));
                    }
  });
  return this;
}
 
Example #18
Source File: BusTest.java    From vertx-shell with Apache License 2.0 6 votes vote down vote up
private void assertSend(TestContext context, String address, Object body, DeliveryOptions options, int times) {
  context.assertTrue(times > 0, "Could not send message " + body + " to address " + address);
  vertx.eventBus().request(address, body, options, ar -> {
    if (ar.failed()) {
      ReplyException ex = (ReplyException) ar.cause();
      if (ex.failureType() == NO_HANDLERS) {
        // Wait 10 ms to be sure consumer is deployed
        vertx.setTimer(10, id -> {
          assertSend(context, address, body, options, times - 1);
        });
      } else {
        context.fail();
      }
    }
  });
}
 
Example #19
Source File: ExecuteEventbusObject.java    From vxms with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(DeliveryOptions deliveryOptions) {
  Objects.requireNonNull(deliveryOptions);
  new ExecuteEventbusObject(
          methodId,
          vxmsShared,
          failure,
          errorMethodHandler,
          message,
          chain,
          objectSupplier,
          excecuteEventBusAndReply,
          encoder,
          errorHandler,
          onFailureRespond,
          deliveryOptions,
          retryCount,
          delay,
          timeout,
          circuitBreakerTimeout)
      .execute();
}
 
Example #20
Source File: OrderServiceVertxEBProxy.java    From vertx-blueprint-microservice with Apache License 2.0 6 votes vote down vote up
public OrderService retrieveOrdersForAccount(String accountId, Handler<AsyncResult<List<Order>>> resultHandler) {
  if (closed) {
    resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("accountId", accountId);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "retrieveOrdersForAccount");
  _vertx.eventBus().<JsonArray>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      resultHandler.handle(Future.failedFuture(res.cause()));
    } else {
      resultHandler.handle(Future.succeededFuture(res.result().body().stream().map(o -> o instanceof Map ? new Order(new JsonObject((Map) o)) : new Order((JsonObject) o)).collect(Collectors.toList())));
    }
  });
  return this;
}
 
Example #21
Source File: JobServiceVertxEBProxy.java    From vertx-kue with Apache License 2.0 6 votes vote down vote up
public JobService getJobLog(long id, Handler<AsyncResult<JsonArray>> handler) {
  if (closed) {
    handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("id", id);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "getJobLog");
  _vertx.eventBus().<JsonArray>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      handler.handle(Future.failedFuture(res.cause()));
    } else {
      handler.handle(Future.succeededFuture(res.result().body()));
    }
  });
  return this;
}
 
Example #22
Source File: PortfolioServiceVertxEBProxy.java    From vertx-microservices-workshop with Apache License 2.0 6 votes vote down vote up
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())));
                    }
  });
}
 
Example #23
Source File: JobServiceVertxEBProxy.java    From vertx-kue with Apache License 2.0 6 votes vote down vote up
public JobService cardByType(String type, JobState state, Handler<AsyncResult<Long>> handler) {
  if (closed) {
    handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("type", type);
  _json.put("state", state == null ? null : state.toString());
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "cardByType");
  _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;
}
 
Example #24
Source File: JobServiceVertxEBProxy.java    From vertx-kue with Apache License 2.0 6 votes vote down vote up
public JobService failedCount(String type, Handler<AsyncResult<Long>> handler) {
  if (closed) {
    handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("type", type);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "failedCount");
  _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;
}
 
Example #25
Source File: AccountServiceVertxEBProxy.java    From vertx-blueprint-microservice with Apache License 2.0 6 votes vote down vote up
public AccountService deleteAllAccounts(Handler<AsyncResult<Void>> 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", "deleteAllAccounts");
  _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()));
    }
  });
  return this;
}
 
Example #26
Source File: ProductServiceVertxEBProxy.java    From vertx-blueprint-microservice with Apache License 2.0 6 votes vote down vote up
public ProductService retrieveProductsByPage(int page, Handler<AsyncResult<List<Product>>> resultHandler) {
  if (closed) {
    resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("page", page);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "retrieveProductsByPage");
  _vertx.eventBus().<JsonArray>send(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      resultHandler.handle(Future.failedFuture(res.cause()));
    } else {
      resultHandler.handle(Future.succeededFuture(res.result().body().stream().map(o -> o instanceof Map ? new Product(new JsonObject((Map) o)) : new Product((JsonObject) o)).collect(Collectors.toList())));
    }
  });
  return this;
}
 
Example #27
Source File: CheckoutServiceVertxEBProxy.java    From vertx-blueprint-microservice with Apache License 2.0 6 votes vote down vote up
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())));
                    }
  });
}
 
Example #28
Source File: Examples.java    From vertx-service-proxy with Apache License 2.0 6 votes vote down vote up
public void example1(Vertx vertx) {
  // Assume database service is already deployed somewhere....
  // Save some data in the database
  JsonObject message = new JsonObject();

  message
    .put("collection", "mycollection")
    .put("document", new JsonObject().put("name", "tim"));

  DeliveryOptions options = new DeliveryOptions().addHeader("action", "save");

  vertx.eventBus()
    .request("database-service-address", message, options)
    .onSuccess(msg -> {
      // done
    }).onFailure(err -> {
    // failure
  });
}
 
Example #29
Source File: QueryableVertxEBProxy.java    From vertx-graphql-service-discovery with Apache License 2.0 6 votes vote down vote up
public void queryWithVariables(String graphqlQuery, JsonObject variables, Handler<AsyncResult<QueryResult>> resultHandler) {
  if (closed) {
    resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return;
  }
  JsonObject _json = new JsonObject();
  _json.put("graphqlQuery", graphqlQuery);
  _json.put("variables", variables);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "queryWithVariables");
  _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 QueryResult(res.result().body())));
                    }
  });
}
 
Example #30
Source File: ExecuteEventbusString.java    From vxms with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(DeliveryOptions deliveryOptions) {
  Objects.requireNonNull(deliveryOptions);
  new ExecuteEventbusString(
          methodId,
          vxmsShared,
          failure,
          errorMethodHandler,
          message,
          chain,
          stringSupplier,
          excecuteAsyncEventBusAndReply,
          errorHandler,
          onFailureRespond,
          deliveryOptions,
          retryCount,
          timeout,
          delay,
          circuitBreakerTimeout)
      .execute();
}