Java Code Examples for io.vertx.core.eventbus.DeliveryOptions#addHeader()

The following examples show how to use io.vertx.core.eventbus.DeliveryOptions#addHeader() . 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: 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 2
Source File: StoreCRUDServiceVertxEBProxy.java    From vertx-blueprint-microservice with Apache License 2.0 6 votes vote down vote up
public void removeStore(String sellerId, Handler<AsyncResult<Void>> 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", "removeStore");
  _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()));
    }
  });
}
 
Example 3
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 4
Source File: ProductServiceVertxEBProxy.java    From vertx-blueprint-microservice with Apache License 2.0 6 votes vote down vote up
public ProductService addProduct(Product product, Handler<AsyncResult<Void>> resultHandler) {
  if (closed) {
    resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("product", product == null ? null : product.toJson());
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "addProduct");
  _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: JobServiceVertxEBProxy.java    From vertx-kue with Apache License 2.0 6 votes vote down vote up
public JobService removeJob(long id, Handler<AsyncResult<Void>> 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", "removeJob");
  _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;
}
 
Example 6
Source File: CounterServiceVertxEBProxy.java    From vertx-blueprint-microservice with Apache License 2.0 6 votes vote down vote up
public void retrieveThenAdd(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", "retrieveThenAdd");
  _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()));
    }
  });
}
 
Example 7
Source File: JobServiceVertxEBProxy.java    From vertx-kue with Apache License 2.0 6 votes vote down vote up
public JobService jobRange(long from, long to, String order, Handler<AsyncResult<List<Job>>> handler) {
  if (closed) {
    handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("from", from);
  _json.put("to", to);
  _json.put("order", order);
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "jobRange");
  _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().stream().map(o -> o instanceof Map ? new Job(new JsonObject((Map) o)) : new Job((JsonObject) o)).collect(Collectors.toList())));
    }
  });
  return this;
}
 
Example 8
Source File: ShoppingCartServiceVertxEBProxy.java    From vertx-blueprint-microservice with Apache License 2.0 6 votes vote down vote up
public ShoppingCartService addCartEvent(CartEvent event, Handler<AsyncResult<Void>> resultHandler) {
  if (closed) {
    resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("event", event == null ? null : event.toJson());
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "addCartEvent");
  _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 9
Source File: PortfolioServiceVertxEBProxy.java    From vertx-microservices-workshop with Apache License 2.0 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 10
Source File: PortfolioServiceVertxEBProxy.java    From vertx-microservices-workshop with Apache License 2.0 6 votes vote down vote up
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())));
                    }
  });
}
 
Example 11
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 12
Source File: AccountServiceVertxEBProxy.java    From vertx-blueprint-microservice with Apache License 2.0 6 votes vote down vote up
public AccountService deleteAccount(String id, Handler<AsyncResult<Void>> 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", "deleteAccount");
  _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 13
Source File: CounterServiceVertxEBProxy.java    From vertx-blueprint-microservice with Apache License 2.0 6 votes vote down vote up
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()));
    }
  });
}
 
Example 14
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 15
Source File: HelloServiceVertxEBProxy.java    From vertx-rx with Apache License 2.0 6 votes vote down vote up
@Override
public void hello(JsonObject name, Handler<AsyncResult<String>> resultHandler){
  if (closed) {
    resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return;
  }
  JsonObject _json = new JsonObject();
  _json.put("name", name);

  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "hello");
  _vertx.eventBus().<String>request(_address, _json, _deliveryOptions, res -> {
    if (res.failed()) {
      resultHandler.handle(Future.failedFuture(res.cause()));
    } else {
      resultHandler.handle(Future.succeededFuture(res.result().body()));
    }
  });
}
 
Example 16
Source File: AccountServiceVertxEBProxy.java    From vertx-blueprint-microservice with Apache License 2.0 6 votes vote down vote up
public AccountService updateAccount(Account account, Handler<AsyncResult<Account>> resultHandler) {
  if (closed) {
    resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
    return this;
  }
  JsonObject _json = new JsonObject();
  _json.put("account", account == null ? null : account.toJson());
  DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
  _deliveryOptions.addHeader("action", "updateAccount");
  _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 17
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 18
Source File: PortfolioServiceVertxEBProxy.java    From vertx-kubernetes-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 19
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 20
Source File: TestServiceProxy.java    From nubes with Apache License 2.0 5 votes vote down vote up
@Test
public void testServiceIsProxified(TestContext context) {
  Async async = context.async();
  String msg = "No problem is too big to run away from";
  JsonObject json = new JsonObject();
  json.put("original", msg); // the name of the param as declared in the method, service-proxy is pretty clever
  DeliveryOptions options = new DeliveryOptions();
  options.addHeader("action", "echo");
  vertx.eventBus().send("service.parrot", json, options, reply -> {
    context.assertTrue(reply.succeeded());
    context.assertEquals(msg, reply.result().body());
    async.complete();
  });
}