Reactive programming .toBlocking()

I use couchbase in Spring Webflux project.
When client call API, I want to search from couchbase and return the results asynchronously.

bucket
.async()
.query(ViewQuery.from("my_design_doc", "my_view"))
.flatMap(AsyncViewResult::rows)
.flatMap(AsyncViewRow::document)
.flatMap(doc-> rx.Observable.just(doc.content()))
.map(list-> {
         someFunction(list);
         return list;
)
.toblocking()
.single();

The code above returns List of JsonObject. I know that To call toblocking() function is Synchronization and it is generally inappropriate for production applications. Is there a way to act asynchronously??
and this code is good way to use in production applications?? plz help me.

@Jingon-Park thanks for your interest! Before you dive any further into this, I would recommend two things:

  • Please use Java SDK 3 instead of SDK 2, since this will put you on a more modern foundation, also for reactive programming.
  • We do not recommend building views for new applications, please consider N1QL instead.

Aside from this: there is nothing wrong with blocking code if it performs fine for your application - it will certainly make things easier to reason about.

If you really want / need to use reactive, that’s fine too! In SDK 3 the reactive() APIs will provide Mono and Flux reactor APIs which are also natively supported by the spring ecosystem and you can plug it in there directly.

1 Like