I am using ParallelFlux for running many task.
but when i am receiving webClient response using bodyToFlux method its merging all the output response instead of getting one by one.
i want the output should be one by one not single string, is there any other method instead of bodyToFLux need to use.
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
Asked
Active
Viewed 2,987 times
0

Shekhar Rathore
- 55
- 2
- 6
-
Please fix your formatting, and it is not merging it until you call subscribe. Why are you subscribing? – Toerktumlare Sep 15 '20 at 14:11
-
changed the format, subscribing it for checking the response. – Shekhar Rathore Sep 16 '20 at 06:39
-
You should not subscribe unless you are the consumer. Usually the sonsumer is the calling client. – Toerktumlare Sep 16 '20 at 08:17
-
yes, but here i wrote the example and wanted to know how parallel flux work and how we can get the out put as list not as a single string on webclient. is there any other way i can try? – Shekhar Rathore Sep 16 '20 at 16:02
-
i got one solution instead of returning flux
create on ResponseBody class with variable want to return it will work fine. – Shekhar Rathore Sep 16 '20 at 18:29
1 Answers
0
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.
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);

Shekhar Rathore
- 55
- 2
- 6