How to do batch(update with select) processing in Couchbase by using AsynCluster and without using reactive in couchbase SDK 3.x?

I have a requirement where I want to update 1000 records in the Couchbase and get the ids of the updated record back. I don’t want to use Reactive (project reactor) as mentioned in the official document of couchbase SDK 3.x.

there is one more approach where we can use the CompletableFuture on the service side and call the AsynCluster.query(queryStatment) which also return CompletableFuture back.

is there any way to perform 1000 update(to be precise update with select "UPDATE bucketName SET docType = ‘abc’ “WHERE caseId = 123 RETURNING caseId as caseId ;”) operation and return caseID back and do this task asynchronously.

i tried with below code but not sure about it.

    List <CompletableFuture<QueryResult>> completableFutureList = new ArrayList<>();
    for(JsonObject j : jsonObjectList) {
  CompletableFuture.allOf(completableFutureList.toArray(new CompletableFuture[0]))
            .exceptionally(ex-> null).join();

it should work asynchronously and return the list of caseIds that are successfully updated and also handle any exception that occurred while doing the update operation and catch that separately.

@SalmanSanjeetwala project reactor was meant to exactly help with dealing with async flows like yours. What’s the reason you cannot / don’t want to use it?

Hi @daschl, Our service is hosted on Tomcat server. If we use project reactor to implement the async flow, we have the following question:
We create a HTTP request to the service to run couchbase operations using Reactor through ReactiveCluster/AsyncCluster. Does the same thread sends back the response from the service or a different thread from the thread pool?


@SalmanSanjeetwala by default, both for async and reactive the thread inside the callback is going to be the I/O pool of couchbase. So in both cases you must not block in the callback threads or otherwise the I/O event loops of our netty runtime are stalled.