Reputation: 67
I'm trying to make a BFF that returns 3 attributes from 3 different clients, the response should look like this: Mono<ExampleClass'>:
{
name: "Exemple", // <- nameClient
value: 20.0, // <- valueClient
otherValue: 25.0 // <- otherValueClient
}
I tried to do this:
return nameClient
.getName(clientId)
.zipWith( valueClient.getValue(id))
.zipWith( otherValueClient.getOtherValue(id))
.map {
Product(it.t1.t1.name, it.t1.t2.value, it.t2.otherValue) }
}
The problem is that i'm getting a tuple with other tuple inside: Tuple2<Tuple2<value,value>,value> and i'm not getting the second value of inside tuple. Is there another way to build better this response?
Upvotes: 0
Views: 111
Reputation: 11216
You can use the static method of zip
in the Mono
class
Mono.zip(nameClient,valueClient,otherValueClient)
This will give you a Tuple3
when all three Mono
s complete
If you need one Mono to complete, in order to use it's value in following Mono's, but still want to zip them all together you could do something like the following
nameClient
.getName(clientId)
.flatMap(name ->
Mono.zip(
Mono.just(name),
valueClient.getValue(name),
otherValueClient.getValue(name)
)
)
Upvotes: 3