问题描述
-
我正在使用ParallelFlux运行许多任务。
-
但是当我使用bodyToFlux方法接收webClient响应时,它会合并所有输出响应,而不是一一得到。
-
我希望输出应该是一个一个而不是一个字符串,是否还有其他方法需要代替bodyToFLux使用。
请求方法:
Flux<String> responsePost = webClient.build() //removed get,url and retrieve here .bodyToFlux(String.class); responsePost.subscribe(s -> { //display response });
响应方法:
public ParallelFlux<String> convertListToMap() { //created list of string str return Flux.fromIterable(str) .parallel(3) .runOn(Schedulers.parallel()) .map( s -> { //some logic here }); }
输出:
parallel fulx reponse: springwebfluxparellelExample
解决方法
-
在这里创建而不是返回ParallelFlux 要返回变量的ResponseBody类,将您的响应分配给 变量,并将其返回给API函数的调用者。
public ParallelFlux<ResponseBody> convertListToMap() { //created list of string str return Flux.fromIterable(str) .parallel(3) .runOn(Schedulers.parallel()) .map( s -> { //some logic here }); } Flux<String> responsePost = webClient.build() //removed get,url and retrieve here .bodyToFlux(ResponseBody.class);