Mono Slice与春季反应性cassandra中的数据转换

问题描述 投票:0回答:1

在阅读了新的春季数据casandra文档(here)后,它说现在有Mono<Slice<T>>支持反应性cassandra。这很好,因为在我的团队中,我们希望对我们的反应性响应实施某种分页。所以我们很高兴从Flux<T>转移到Mono<Slice<T>>但是有这个问题,我们使用flux.map对我们的通量数据进行转换,但是对于没有阻塞的Slice来说这似乎是不可能的。

例如,我们有这个功能:

Flux<Location> resp = repository.searchLocations(searchFields).map(this::transformLocation);

其中transformLocation是一个函数,它接收数据库对象并返回一个用户友好的对象,其中包含更多用户友好的数据。你将如何用Mono<Slice<Location>>实现这一目标?

从我所看到的Slice,你可以使用getContent获取数据,但是返回一个列表,这不会像阻塞一样吗?

spring-webflux project-reactor spring-data-cassandra
1个回答
2
投票

您可以使用从getContent() method获得的列表,以创建您之前所做的通量。

Mono<Slice<Location>> sliceMono; //this is just another mono on which you can operate

Flux<location> intermediateResp = sliceMono.flatMap(slice -> Flux.fromIterable(slice.getContent()));

//you can now transform this intermediateResp flux as you were doing before, can't you?

这不符合您的目的,还是您需要其他东西?

(代码是在没有IDE帮助的情况下编写的,所以用它来理解方法)

© www.soinside.com 2019 - 2024. All rights reserved.