Using Mono<T> in Spring to populate a Cloud Firestore entity

Harold L. Brown :

I am using spring-cloud-gcp-starter-data-firestore for accessing Google Cloud Firestore in my Java Spring application.

Currently, my entity looks like this:

public class Subscription {

    public String userId;
    public String companyId;

    // other properties

}

However, I obtain the userId and companyId via a reactor.core.publisher.Mono in org.springframework.security.core.context.ReactiveSecurityContextHolder.

How can I persist both properties which are nested inside Monos without resorting to Mono#block?

Harold L. Brown :

I am now using Mono#zipWith to combine both Monos. Then I am creating the entity inside Mono#flatMap.

service.getCompanyId()
   .zipWith(service.getUserId())
   .flatMap(objects -> createEntity(objects.getT1(), objects.getT2()))

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=356543&siteId=1