I am using vertx-rx-java
I have a handler where I need to make 2 different requests via EventBus and create response using responses from these 2 requests.
public handle(RoutingContext context) {
....some code...
Single<Message<Object>> firstRequest = eb.rxSend("address1", "message1");
Single<Message<Object>> secondRequest = eb.rxSend("address2", "message2");
... TODO ...
}
Basically I need to combine two request results and put them into RoutingContext response. The problem is that I don't completely understand how to do that in rxjava style.
The only way I was able to think of is smth like that:
firstRequest.doOnSuccess(resp1 -> {
secondRequest.doOnSuccess(resp2 -> {
});
});
But I think it's a bad way because what if there are 10 requests instead of 2? this code will have 10 nested calls.
Is there any better ways to combine multiple requests results?