简体   繁体   English

使用 bodyToFlux 方法的 webClient 响应合并所有接收到的响应而不是将其分离

[英]webClient response using bodyToFlux method merging all the received response instead separating it out

  1. I am using ParallelFlux for running many task.我正在使用 ParallelFlux 来运行许多任务。

  2. but when i am receiving webClient response using bodyToFlux method its merging all the output response instead of getting one by one.但是当我使用 bodyToFlux 方法接收 webClient 响应时,它会合并所有输出响应,而不是一一获取。

  3. i want the output should be one by one not single string, is there any other method instead of bodyToFLux need to use.我希望输出应该是一个一个而不是单个字符串,是否需要使用其他方法而不是 bodyToFLux。

    request method:请求方法:

     Flux<String> responsePost = webClient.build() //removed get,url and retrieve here .bodyToFlux(String.class); responsePost.subscribe(s -> { //display response });

    response method:应对方法:

     public ParallelFlux<String> convertListToMap() { //created list of string str return Flux.fromIterable(str) .parallel(3) .runOn(Schedulers.parallel()) .map( s -> { //some logic here }); }

    output:输出:

     parallel fulx reponse: springwebfluxparellelExample
  1. Here instead of returning ParallelFlux create an ResponseBody class with variable you want to return, assign your response to variable inside ResponseBody and return it to caller of API function.在这里,不是返回 ParallelFlux,而是创建一个带有要返回的变量的 ResponseBody 类,将您的响应分配给 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM