I am trying to make calls with the following order:
save an object
publish an object creation event, only if the first step is done
Return a Flux list What I have currently is following:
return dbSaveObject(object) //this returns Mono of created object .doOnSuccess(s -> hermes.publishEvent(CREATE)) //publishEvent() here returns Mono<Void> .thenMany(Flux.just(object))
Would this work and publish event as requested, or should I use zipWhen() instead of doOnSuccess()?
Advertisement
Answer
doOn...
are so-called side-effect operators and should not be used for constructing reactive flows.
In case publishEvent
returns Mono<Void>
you could use the following
return dbSaveObject(object) .flatMap(savedObject -> hermes.publishEvent(CREATE) .thenReturn(savedObject) );