0

我是反应组件的新手。我使用 webclient 进行了 api 调用,响应被包装在 Mono 组件中。有没有办法检查分配给接收到的 Mono 组件中的对象类的值。

收到的响应包装在 Mono<Abc.class> 中。

class Abc {
  private message;
  private email;
  private status;
}

我想获取消息、电子邮件、状态中的值。

我尝试使用 .block() 但收到的错误 block()/blockfirst()/blocklast() 是阻塞的,线程 reactor-http-nio-4 不支持。

先感谢您。

4

1 回答 1

0

如果您想接收 Mono/Flux 中的值,请在 Mono 中使用flatMap,如下所示。设 abc 为 Abc 类的实例。

Mono.just(abc).flatMap(fields ->{
       String message = fields.getMessage();
       String email = fields.getEmail();
       String status = fields.getStatus();
       //use these values as you want to
       return Mono.just(fields);
    });
于 2020-07-28T15:21:52.253 回答