The index() method takes a strongly typed Person object and sends it over to Elasticsearch. First the doIndex() method makes the actual call to Elasticsearch, marshalling Person to JSON. Having Elastic's result of type ActionListener<IndexResponse> we convert it to Mono<IndexResponse>. This is done via listenerToSink() helper method. The sequence of compose() methods are an elegant way to apply a series of metrics:

get() method tries to find a document in Elasticsearch by "userName". Newcomers to RxJava or Reactor are very eager to call subscribe() or block*(). Interestingly none of these are needed in Spring WebFlux. You create a bunch of Monos or Fluxes, pass them through a series of transformations and return from your controller. Just works™.

put() method is equally simple. For debug purposes I convert IndexResponse to JSON in toMap() method, but this isn't necessary. As you can see building reactive applications in Spring WebFlux is quite simple. We no longer need any adapting layers or blocking code. Everything is fully asynchronous and event-driven. Moreover in this setup (see source code) there are no servlets or Jetty/Tomcat on the CLASSPATH!

Spring has built-in reactive support for some databases like MongoDB. In these blog posts I gave you an overview how to integrate Reactor with Spring and other databases that provide non-blocking API. You can easily adjust code samples to use it with other sources and data stores.