Couchbase Java SDK 3.x and N1QL Metrics issue


I am trying to print the n1ql metrics but not able to do so. Can someone please advice.

                .query(n1ql, queryOptions().metrics(true))
                .flatMapMany(result -> {
          "{}", new LogEvent("queryFromBucket", traceId).addEntry("n1ql", n1ql).addEntry("metrics", result.metaData().metrics().block()));
                    return result.rowsAsObject();

Hi @himanshu.mps

You shouldn’t do any blocking operations inside a Reactive operator. Here you’re blocking on the metadata Mono, inside the operator for the rows Flux. Try flatMap-ping to the metadata Mono instead. E.g. something like result.rowsAsObject().flatMap(rows -> result.metaData().doOnNext( … ))

Also bear in mind that on the wire, the metadata is received after the rows, so if you want to stream the rows then handle the metadata, you don’t want to do anything that blocks on the metadata first.

@graham.pople I want to return flowable of JsonObject after running the n1ql. Should I be using flatmapmany or any other option ?

This will do it:

        Flux<JsonObject> out = cluster.reactive()
            .query("select 'hello' as greeting",
            .flatMapMany(result ->
                            .concatMap(rows ->
                                    result.metaData().doOnNext(metaData ->
                                            // At this point have both rows and metadata

    List<JsonObject> rows = out.collectList().block();

Once you have the Flux, trivial to use RxJava2Adapter.fluxToFlowable on it of course.