Spring Webflux 将 null 返回给控制器

问题描述

每次我认为我了解 Webflux 和项目反应器时,我发现我不知道。 所以我进行了一些 API 调用……我想先调用 1 ……取回信息,使用该信息进行后续调用

所以我这样做

public Mono<ResponSEObject> createAggregatedRecords(RecordToPersist recordToPersist){
return randomapiclient.createRecord(recordToPersist)
    .flatMap(result -> {
        return Mono.zip(
                webClientInstance.createOtherRecord1(result.getChildRecord1()),webClientInstance2.createOtherRecord2(result.getChildRecord2()),webClientInstance3.createOtherRecord3(result.getChildRecord3()))
                .map(tupple -> {
                        ResponSEObject respObj = new ResponSEObject();
                        respObj.setChildResult1(tupple.getT1());
                        respObj.setChildResult2(tupple.getT2());
                        respObj.setChildResult3(tupple.getT3());
                        return respObj;
                }
    }).doOnSuccess(res -> log.info("This throws an error: {}",res.getChildResult1.getFirstField()))
}

现在,出于某种原因,我将带有此代码的空对象返回给我的控制器,并且我没有在 Json 中打印出该对象。

我怀疑这是因为我将 Mono.zip 嵌套在平面图中,并且没有正确返回结果。我正在执行所有这些 API 调用,因为我的端到端集成测试取得了成功。

现在我想我会从 Mono.zip 链中的 .map 函数返回该响应对象,然后将其返回到链中的 flatMap 调用。如果我像 doOnSuccess 一样将观察者放在链上并打印出响应对象字段,我会得到一个空指针......不知道我错过了什么

  1. 这是实现该目标的好模式吗?或者我应该尝试不同的路径?
  2. 为什么我不能让响应对象返回?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)