使用 Spring 中的 Mono<T> 填充 Cloud Firestore 实体
Using Mono<T> in Spring to populate a Cloud Firestore entity
我在 Java Spring 应用程序中使用 spring-cloud-gcp-starter-data-firestore
for accessing Google Cloud Firestore。
目前,我的实体如下所示:
public class Subscription {
public String userId;
public String companyId;
// other properties
}
但是,我通过 reactor.core.publisher.Mono
in org.springframework.security.core.context.ReactiveSecurityContextHolder
.
获得了 userId
和 companyId
如何在不求助于 Mono#block
的情况下保留嵌套在 Mono
中的两个属性?
我现在使用 Mono#zipWith
来组合两个 Mono
。然后我在 Mono#flatMap
.
中创建实体
service.getCompanyId()
.zipWith(service.getUserId())
.flatMap(objects -> createEntity(objects.getT1(), objects.getT2()))
我建议按照 Google codelab 中的教程进行操作。
Here你会发现Firestore可以是Datastore模式,这让之前的教程更适合你。
我在 Java Spring 应用程序中使用 spring-cloud-gcp-starter-data-firestore
for accessing Google Cloud Firestore。
目前,我的实体如下所示:
public class Subscription {
public String userId;
public String companyId;
// other properties
}
但是,我通过 reactor.core.publisher.Mono
in org.springframework.security.core.context.ReactiveSecurityContextHolder
.
userId
和 companyId
如何在不求助于 Mono#block
的情况下保留嵌套在 Mono
中的两个属性?
我现在使用 Mono#zipWith
来组合两个 Mono
。然后我在 Mono#flatMap
.
service.getCompanyId()
.zipWith(service.getUserId())
.flatMap(objects -> createEntity(objects.getT1(), objects.getT2()))
我建议按照 Google codelab 中的教程进行操作。
Here你会发现Firestore可以是Datastore模式,这让之前的教程更适合你。