在 spring 反应式卡桑德拉中进行数据转换的 Mono Slice
Mono Slice with data transformation in spring reactive cassandra
阅读新的 spring data casandra 文档 (here) 后,它说现在 Mono<Slice<T>>
支持反应式 cassandra。
这很好,因为在我的团队中,我们希望对我们的反应性响应实施某种分页。所以我们很高兴从 Flux<T>
移动到 Mono<Slice<T>>
但存在这个问题,我们使用 flux.map 对通量数据进行转换,但 Slice 似乎不可能没有阻塞。
例如,我们有这个功能:
Flux<Location> resp = repository.searchLocations(searchFields).map(this::transformLocation);
其中 transformLocation 是一个接收数据库对象的函数,returns 是一个对用户更友好的对象,具有对用户更友好的数据。
你将如何通过 Mono<Slice<Location>>
实现这一目标?
据我所见的Slice,getContent可以获取到数据,但是returns一个list,会不会像blocking一样?
您可以使用从 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写的代码,所以用它来理解方法)
阅读新的 spring data casandra 文档 (here) 后,它说现在 Mono<Slice<T>>
支持反应式 cassandra。
这很好,因为在我的团队中,我们希望对我们的反应性响应实施某种分页。所以我们很高兴从 Flux<T>
移动到 Mono<Slice<T>>
但存在这个问题,我们使用 flux.map 对通量数据进行转换,但 Slice 似乎不可能没有阻塞。
例如,我们有这个功能:
Flux<Location> resp = repository.searchLocations(searchFields).map(this::transformLocation);
其中 transformLocation 是一个接收数据库对象的函数,returns 是一个对用户更友好的对象,具有对用户更友好的数据。
你将如何通过 Mono<Slice<Location>>
实现这一目标?
据我所见的Slice,getContent可以获取到数据,但是returns一个list,会不会像blocking一样?
您可以使用从 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写的代码,所以用它来理解方法)