Receiving objects reactively

Now, we understand how to return objects reactively, but how we can accept them? When we create a reactive microservice, Spring can send to our RequestMapping a Mono publisher that will have the object in the body when we subscribe to it. But we need to make our service accept a Mono with a promise of a value, so first let's modify our service interface:

package com.microservices.chapter4import reactor.core.publisher.Fluximport reactor.core.publisher.Monointerface CustomerService {  fun getCustomer(id: Int) : Mono<Customer?>  fun searchCustomers(nameFilter: String): Flux<Customer>  fun createCustomer(customerMono: Mono<Customer>) : Mono<*>}

Why have we set the result of our function to be a Mono? When we create a ...

Get Hands-On Microservices with Kotlin now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.