diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Client.java b/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Client.java index 9afe50af58..bbfc88322b 100644 --- a/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Client.java +++ b/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Client.java @@ -41,28 +41,25 @@ public class Client { .bodyToMono(User.class); } - public List fetchUsers(List userIds) { + public Flux fetchUsers(List userIds) { return Flux.fromIterable(userIds) .parallel() .runOn(Schedulers.elastic()) .flatMap(this::getUser) - .collectSortedList((u1, u2) -> u2.id() - u1.id()) - .block(); + .ordered((u1, u2) -> u2.id() - u1.id()); } - public List fetchUserAndOtherUser(int id) { + public Flux fetchUserAndOtherUser(int id) { return Flux.merge(getUser(id), getOtherUser(id)) .parallel() .runOn(Schedulers.elastic()) - .collectSortedList((u1, u2) -> u2.id() - u1.id()) - .block(); + .ordered((u1, u2) -> u2.id() - u1.id()); } - public UserWithItem fetchUserAndItem(int userId, int itemId) { + public Mono fetchUserAndItem(int userId, int itemId) { Mono user = getUser(userId).subscribeOn(Schedulers.elastic()); Mono item = getItem(itemId).subscribeOn(Schedulers.elastic()); - return Mono.zip(user, item, UserWithItem::new) - .block(); + return Mono.zip(user, item, UserWithItem::new); } } diff --git a/spring-5-reactive-client/src/test/java/com/baeldung/reactive/webclient/simultaneous/ClientIntegrationTest.java b/spring-5-reactive-client/src/test/java/com/baeldung/reactive/webclient/simultaneous/ClientIntegrationTest.java index 0acedf15b0..d74a64d9c9 100644 --- a/spring-5-reactive-client/src/test/java/com/baeldung/reactive/webclient/simultaneous/ClientIntegrationTest.java +++ b/spring-5-reactive-client/src/test/java/com/baeldung/reactive/webclient/simultaneous/ClientIntegrationTest.java @@ -56,7 +56,9 @@ public class ClientIntegrationTest { // Act long start = System.currentTimeMillis(); - List users = client.fetchUsers(userIds); + List users = client.fetchUsers(userIds) + .collectList() + .block(); long end = System.currentTimeMillis(); // Assert