datastax / cassandra-quarkus

An Apache Cassandra(R) extension for Quarkus
Apache License 2.0
40 stars 28 forks source link

Provide a lazy wrapper for QuarkusCqlSession #106

Closed adutra closed 3 years ago

adutra commented 4 years ago

Instead of injecting CompletionStage<QuarkusCqlSession> we could provide a session wrapper so that users can inject QuarkusCqlSession directly and avoid blocking Vertx threads even if they opt out from eager init at startup.

┆Issue is synchronized with this Jira Task by Unito

adutra commented 4 years ago

Alternatively we can explore the idea of exposing two beans: CompletionStage<QuarkusCqlSession> and QuarkusCqlSession, something like:

  @Produces
  @ApplicationScoped
  @Unremovable
  public CompletionStage<QuarkusCqlSession> createCassandraClientAsync() {
    ...
    QuarkusCqlSessionBuilder builder =
        new QuarkusCqlSessionBuilder()
            .withMetricRegistry(metricRegistry)
            .withQuarkusEventLoop(mainEventLoop)
            .withConfigLoader(configLoaderBuilder.build());
    return builder.buildAsync();
  }

  @Produces
  @ApplicationScoped
  @Unremovable
  public QuarkusCqlSession createCassandraClient(CompletionStage<QuarkusCqlSession> sessionFuture) {
    return CompletableFutures.getUninterruptibly(sessionFuture);
  }
adutra commented 4 years ago

Note that this may be complicated by the presence of mapper/daos, since these components would have to be produced as CompletionStage<...> as well.