Reactive programming 如何链接来自不同服务的响应,以便使用';这些回答';在WebFlux中? 关于问题的语境化:

Reactive programming 如何链接来自不同服务的响应,以便使用';这些回答';在WebFlux中? 关于问题的语境化:,reactive-programming,spring-webflux,project-reactor,spring-data-mongodb-reactive,webflux,Reactive Programming,Spring Webflux,Project Reactor,Spring Data Mongodb Reactive,Webflux,我试图链接来自多个服务的数据,以便聚合/合并它们的响应 我的目标是通过“合并响应”创建的对象列表创建最终通量 合并基于2个服务(userService+postService) 以下是上述情况的代码: 代码: @Slf4j @服务 @AllArgsConstructor 公共类BlogService实现BlogServiceInt{ 私有最终用户服务INT用户服务; 私人最终邮政服务国际邮政服务; 私人最终评论服务INT评论服务; 私有最终模型映射器conv; @凌驾 公共流量findAl

我试图链接来自多个服务的数据,以便聚合/合并它们的响应

  • 我的目标是通过“合并响应”创建的对象列表创建最终通量

  • 合并基于2个服务(userService+postService)

  • 以下是上述情况的代码:
  • 代码:
    @Slf4j
    @服务
    @AllArgsConstructor
    公共类BlogService实现BlogServiceInt{
    私有最终用户服务INT用户服务;
    私人最终邮政服务国际邮政服务;
    私人最终评论服务INT评论服务;
    私有最终模型映射器conv;
    @凌驾
    公共流量findAllShowAllDto(){
    返回用户服务
    .findAll()
    .flatMap(user->Flux.fromIterable(List.of)(conv.map(user,UserAllDto.class)))
    .flatMap(userAllDto->{
    邮政服务
    .findPostsByAuthorId(userAllDto.getId())
    .map(post->conv.map(post,PostAllDto.class))
    .LIST()
    .flatMap(列表->{
    如果(!list.isEmpty())userAllDto.setPosts(list);
    返回Mono.just(userAllDto);
    });
    返回flow.fromIterable(List.of(userAllDto));
    }
    );
    }
    }
    
    问题:
    • 如何完成“userAllDto.setPosts”,
      • 通过获取“PostAllDto”对象并创建该对象的列表,
        • 并在“userAllDto.setPosts”中插入此列表
    当前有问题的JsonResponse(邮递员):
    [
    {
    “id”:“60b0306f275ea3018b167dde”,
    “名称”:“p”,
    “员额”:[]
    },
    {
    “id”:“60b03070275ea3018b167ddf”,
    “名称”:“p”,
    “员额”:[
    {
    “id”:空,
    “标题”:空,
    “列表注释”:[]
    }
    ]
    }
    ]
    
    更新: 解决方案

    @覆盖
    公共流量findAllShowAllDto(){
    返回userRepo
    .findAll()
    .flatMap(用户->{
    UserAllDto userDto=mapper.map(user,UserAllDto.class);
    最终Mono用户AlldToMono=
    邮政服务
    .findPostsByAuthorId(userDto.getId())
    .flatMap(post->{
    PostAllDto postDto=mapper.map(post,PostAllDto.class);
    最终单声道Postalldtomino=
    commentService.findCommentsByPostId(postDto.getPostId())
    .map(c->mapper.map(c,CommentAllDto.class))
    .LIST()
    .flatMap(列表->{
    postDto.setListComments(列表);
    返回Mono.just(postDto);};
    返回postAllDtoMono.flux();})
    .LIST()
    .flatMap(列表->{
    userDto.setPosts(列表);
    返回Mono.just(userDto);
    });
    返回userAllDtoMono.flux();
    });
    }
    
    解决方案的JsonResponse(邮递员):

    [
    {
    “id”:“60b9284e08a653638c22bd97”,
    “名称”:“bbbbbbbb”,
    “员额”:[
    {
    “postId”:“60b929a808a653638c22bd9d”,
    “头衔”:“BBBBBBBB 111111111”,
    “idAuthor”:“60b9284e08a653638c22bd97”,
    “列表注释”:[
    {
    “commentId:“60b92bad08a653638c22bd9e”,
    “postId”:“60b929a808a653638c22bd9d”,
    “idAuthor”:“60b9292e08a653638c22bd9b”,
    “文本”:“CCCC2222”
    },
    {
    “commentId:“60b92c1708a653638c22bd9f”,
    “postId”:“60b929a808a653638c22bd9d”,
    “idAuthor”:“60b9285908a653638c22bd98”,
    “文本”:“aaaaaaaaaaaaaaaaaaaaaaaa2222”
    }
    ]
    }
    ]
    },
    {
    “id”:“60b9285908a653638c22bd98”,
    “名称”:“AAAAA”,
    “员额”:[
    {
    “postId”:“60b9287808a653638c22bd99”,
    “标题”:“AAAAAA 1111111”,
    “idAuthor”:“60b9285908a653638c22bd98”,
    “列表注释”:[
    {
    “commentId:“60b928f408a653638c22bd9a”,
    “postId”:“60b9287808a653638c22bd99”,
    “idAuthor”:“60b9284e08a653638c22bd97”,
    “文本”:“BBB 1111”
    },
    {
    “commentId:“60b9294a08a653638c22bd9c”,
    “postId”:“60b9287808a653638c22bd99”,
    “idAuthor”:“60b9292e08a653638c22bd9b”,
    “文本”:“CCCC1111”
    }
    ]
    }
    ]
    }
    ]
    

    非常感谢您的帮助

    什么是
    conv
    ?请