Java Code Examples for io.vertx.rxjava.ext.jdbc.JDBCClient#createNonShared()

The following examples show how to use io.vertx.rxjava.ext.jdbc.JDBCClient#createNonShared() . 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: AuditVerticle.java    From vertx-microservices-workshop with Apache License 2.0 6 votes vote down vote up
/**
 * Starts the verticle asynchronously. The the initialization is completed, it calls
 * `complete()` on the given {@link Future} object. If something wrong happens,
 * `fail` is called.
 *
 * @param future the future to indicate the completion
 */
@Override
public void start(Future<Void> future) {
  super.start();

  // creates the jdbc client.
  jdbc = JDBCClient.createNonShared(vertx, config());

  // TODO
  // ----
  Single<MessageConsumer<JsonObject>> readySingle = Single.error(new UnsupportedOperationException("not yet implemented"));
  // ----

  readySingle.doOnSuccess(consumer -> {
    // on success we set the handler that will store message in the database
    consumer.handler(message -> storeInDatabase(message.body()));
  }).subscribe(consumer -> {
    // complete the verticle start with a success
    future.complete();
  }, error -> {
    // signal a verticle start failure
    future.fail(error);
  });
}
 
Example 2
Source File: CartEventDataSourceImpl.java    From vertx-blueprint-microservice with Apache License 2.0 5 votes vote down vote up
public CartEventDataSourceImpl(io.vertx.core.Vertx vertx, JsonObject json) {
  this.client = JDBCClient.createNonShared(Vertx.newInstance(vertx), json);
  // TODO: Should not init the table here.
  client.rxGetConnection()
    .flatMap(connection ->
      connection.rxExecute(INIT_STATEMENT)
        .doAfterTerminate(connection::close)
    )
    .subscribe();
}
 
Example 3
Source File: AuditVerticle.java    From vertx-microservices-workshop with Apache License 2.0 5 votes vote down vote up
/**
 * Starts the verticle asynchronously. The the initialization is completed, it calls
 * `complete()` on the given {@link Future} object. If something wrong happens,
 * `fail` is called.
 *
 * @param future the future to indicate the completion
 */
@Override
public void start(Future<Void> future) {
  super.start();

  // creates the jdbc client.
  jdbc = JDBCClient.createNonShared(vertx, config());

  // ----
  Single<Void> databaseReady = initializeDatabase(config().getBoolean("drop", false));
  Single<Void> httpEndpointReady = configureTheHTTPServer()
      .flatMap(server -> rxPublishHttpEndpoint("audit", "localhost", server.actualPort()));
  Single<MessageConsumer<JsonObject>> messageConsumerReady = retrieveThePortfolioMessageSource();
  Single<MessageConsumer<JsonObject>> readySingle = Single.zip(
      databaseReady,
      httpEndpointReady,
      messageConsumerReady,
      (db, http, consumer) -> consumer);
  // ----

  readySingle.doOnSuccess(consumer -> {
    // on success we set the handler that will store message in the database
    consumer.handler(message -> storeInDatabase(message.body()));
  }).subscribe(consumer -> {
    // complete the verticle start with a success
    future.complete();
  }, error -> {
    // signal a verticle start failure
    future.fail(error);
  });
}