Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring反应器-消耗分页端点_Spring_Spring Webflux_Spring Reactive_Spring Reactor_Spring Mono - Fatal编程技术网

Spring反应器-消耗分页端点

Spring反应器-消耗分页端点,spring,spring-webflux,spring-reactive,spring-reactor,spring-mono,Spring,Spring Webflux,Spring Reactive,Spring Reactor,Spring Mono,这是我第一次使用Spring反应堆,我面临以下挑战: 我有一项服务,允许使用由页码和页面大小指定的大量记录: Mono<GetContactsForGroupResponse> getContactsForGroup(Integer page, Integer size); 现在我需要编写另一个方法,从中读取所有页面 Mono<GetContactsForGroupResponse> getContactsForGroup(Integer page, Integer

这是我第一次使用Spring反应堆,我面临以下挑战:

我有一项服务,允许使用由页码和页面大小指定的大量记录:

 Mono<GetContactsForGroupResponse> getContactsForGroup(Integer page, Integer size);
现在我需要编写另一个方法,从中读取所有页面

Mono<GetContactsForGroupResponse> getContactsForGroup(Integer page, Integer size);
Mono-getContactsForGroup(整型页面,整型大小);
并将结果合并到一个集合中:

Mono<Collection<GetContactsForGroupResponse>> getContactsForGroup();
Mono-getContactsForGroup();
到目前为止,我写了:

            List<GetContactsForGroupResponse> groupContacts = new ArrayList<>();
            AtomicBoolean allPagesConsumed = new AtomicBoolean(false);

            int pageNumber = 0;
            int pageSize = 10;

            while(!allPagesConsumed.get()) {
                allPagesConsumed.set(true);
                GetContactsForGroupResponse getContactsForGroupResponse =
                        getContactsForGroup(accountId, g.getId(), 0, pageSize).block();
                Optional.ofNullable(getContactsForGroupResponse)
                        .ifPresent(r -> {
                            allPagesConsumed.set(r.isLast());
                            groupContacts.add(r);
                        });

                pageNumber ++;
List groupContacts=new ArrayList();
AtomicBoolean allPagesConsumed=新的AtomicBoolean(false);
int pageNumber=0;
int pageSize=10;
而(!allPagesConsumed.get()){
allPagesConsumed.set(true);
GetContactsForGroupResponse GetContactsForGroupResponse=
getContactsForGroup(accountId,g.getId(),0,pageSize).block();
可选。不可用(getContactsForGroupResponse)
.如果存在(r->{
allPagesConsumed.set(r.isLast());
groupContacts.add(r);
});
页码++;
我一页一页地读结果,直到读到最后一页。 我想知道从SpringReactor的角度来看,什么是正确的实现方式

如有任何建议,将不胜感激

谢谢

没有“正确的方法”,因为这不是一个被动的问题

由于您正在获取“页面”,因此您正在处理一种非反应式的数据处理方式。您没有透露有关如何获取这些数据以及从哪种类型的数据库获取这些数据的任何信息

最简单的方法是对数据库进行查询,然后一次性获取所有内容

写一个
getAllContactsForGroup
,不要做while循环。

没有“正确的方法”,因为这不是一个被动的问题

由于您正在获取“页面”,因此您正在处理一种非反应式的数据处理方式。您没有透露有关如何获取这些数据以及从哪种类型的数据库获取这些数据的任何信息

最简单的方法是对数据库进行查询,然后一次性获取所有内容

编写一个
getAllContactsForGroup
,不要执行while循环。

请参阅
            List<GetContactsForGroupResponse> groupContacts = new ArrayList<>();
            AtomicBoolean allPagesConsumed = new AtomicBoolean(false);

            int pageNumber = 0;
            int pageSize = 10;

            while(!allPagesConsumed.get()) {
                allPagesConsumed.set(true);
                GetContactsForGroupResponse getContactsForGroupResponse =
                        getContactsForGroup(accountId, g.getId(), 0, pageSize).block();
                Optional.ofNullable(getContactsForGroupResponse)
                        .ifPresent(r -> {
                            allPagesConsumed.set(r.isLast());
                            groupContacts.add(r);
                        });

                pageNumber ++;