How to efficiently handle transactions with the reactive java driver / clarifications on api

Hi @st-h,

Would you be able to abstract that away in a convenient wrapper or method? Having said that, sometimes you do have to handle them differently, i.e. doOnError() you may not want to only abort.

Depending on your use case and code structure, maybe you could use await to synchronise the transaction part for a different code structure ? for example:

 ObservableSubscriber<ClientSession> sessionSubscriber = new OperationSubscriber<>();
 mongoClient.startSession().subscribe(sessionSubscriber);
 sessionSubscriber.await(5, SECONDS);
        
 try (ClientSession clientSession = sessionSubscriber.getReceived().get(0)) {
     clientSession.startTransaction(TransactionOptions.builder()
                  .writeConcern(WriteConcern.MAJORITY).build());

     // operations .. 

     ObservableSubscriber<Void> commitSubscriber = new OperationSubscriber<>();
     clientSession.commitTransaction().subscribe(commitSubscriber);
     commitSubscriber.await();
}

Unfortunately the convenient withTransactions() API is available on the synchronous version currently (v4.1). There is an open ticket to track this work JAVA-3539, feel free to upvote/watch the ticket to receive notifications on progress.

Regards,
Wan.