【发布时间】:2021-03-05 12:31:59
【问题描述】:
与this question to take a string from a Mono 相关,我想我终于知道如何从Flux<String> 中取出String,如下所示:
Flux<String> rates = controller.getRate(json);
String myRate = rates.next().subscribe(System.out::print);
但是,这会导致类型不匹配 cannot convert from Disposable to String
我做错了什么?
澄清一下,这是为了测试 - 我需要一个内部字符串值。因此,如果我有一个 Flux<String> 的字符串:one、two、three,那么我想将另一个字符串设置为值 one
String s = ...
如果我尝试
String s = rates.doOnNext(System.out::print);
然后我得到一个type mismatch: cannot convert from Flux<String> to String
如果我尝试
String s = next().flatMap(System.out::print);
然后我得到一个type mismatch: cannot convert from Mono<Object> to String
【问题讨论】:
-
Flux::subscribe返回一个不是字符串的一次性用品。 -
String s = rates.doOnNext(System.out::print).blockFirst();有效,但它不是反应性的。
标签: project-reactor