Search code examples
reactive-programmingcouchbasespring-data-couchbase

How to use Atomic counters with Spring Data Couchbase Reactive


I'm using Spring Data couchbase reactive to perform read, write, update operations. Now I have a need for something like Atomic Counters in Couchbase for one of the attributes. I read that Spring reactive doesn't support this ( may it is now) feature yet, so would like guidance about how to go about this.

I have already looked at the solution provided in other ticket: Atomic counters in Spring with Couchbase But this is not blocking calls, so I was wondering if I can have something similar for making non blocking calls as well.

I can use Couchbase's reactive client for this but then it means I need to combine Reactive client of Couchbase and Spring Data Couchbase reactive for which I am not too confident if it is good approach or not.


Solution

  • Atomic counters are not part of the Spring Data specification (Spring Data was originally designed for RDBMS)

    A few options are:

    1) Make a simple sync call via the bucket object:

    myRepository.getCouchbaseOperations().getCouchbaseBucket().counter("mycounter", 1L, 1L );
    

    2) Use the standard Couchbase Java Reactive SDK (RxJava) and convert the Observable: Adapting RxJava 1.1.5 to Reactor Core 3.1.0.M3