use of org.neo4j.driver.async.AsyncSession in project micronaut-neo4j by micronaut-projects.
the class Neo4jHealthIndicator method getResult.
@Override
public Publisher<HealthResult> getResult() {
try {
Mono<HealthResult> healthResultSingle = Mono.create(emitter -> {
AsyncSession session = boltDriver.asyncSession();
CompletionStage<ResultSummary> query = session.writeTransactionAsync(tx -> tx.runAsync("RETURN 1 AS result").thenCompose(ResultCursor::consumeAsync));
query.handleAsync((resultSummaryStage, throwable) -> {
if (throwable != null) {
return buildErrorResult(throwable);
} else {
HealthResult.Builder status = HealthResult.builder(NAME, HealthStatus.UP);
ServerInfo serverInfo = resultSummaryStage.server();
status.details(Collections.singletonMap("server", serverInfo.version() + "@" + serverInfo.address()));
return status.build();
}
}).thenComposeAsync(status -> session.closeAsync().handle((signal, throwable) -> status)).thenAccept(emitter::success);
});
return healthResultSingle.subscribeOn(Schedulers.fromExecutorService(ioExecutor));
} catch (Throwable e) {
return Mono.just(buildErrorResult(e));
}
}
Aggregations