I'm attempting to achieve the following in the method below
- Get All Cars from Dealer X
- Create wrapper object that stores a set of all cars and another set of all manufactures 2a. Populate Cars set with the cars obtained in Step 1
- For each Car get all of their independent manufactures
- Store all obtained manufactures into the wrapper objects manufactures Set
- Return Mono of Car and manufactures
Mono<CarAndManufactures> requestCarAndManufactures(Request req) {
final String dealerId = buildDealerId(req.getDealerRegion(), req.getDealerId());
final CarAndManufactures CarAndManufactures = new CarAndManufactures();
return webSocketClient.getCars(dealerId) //note #getCars returns a Mono
.map(getCarsResponse -> getCarsResponse
.getResult()
.stream()
.map(Car::getId)
.collect(toSet()))
.map(carIds -> {
CarAndManufactures.setCars(carIds);
return CarAndManufactures;
})
.flatMapMany(CarAndManufactures1 -> Flux.fromIterable(CarAndManufactures.getCars().keySet()))
.collectList()
.log("Existing cars")
.flatMap(carIds -> { //This is the problem area
carIds
.stream()
.map(carId -> {
webSocketClient.getManufactures(carId) //Note getManufactures returns a Mono... This method does look like its ever called
.map(getManufactureResponse -> getManufactureResponse
.getResult()
.stream()
.map(Manufacture::getId)
.collect(toSet()))
.map(ManufactureIds -> {
CarAndManufactures.SetManufactures(ManufactureIds); //since the line commented on above is not called the Manufacture Set is empty
return CarAndManufactures;
});
return CarAndManufactures;
});
return just(CarAndManufactures);
}
)
.log("Car And Manufactures");
}
The Set of Manufactures is alway empty doesnt look like webSocketClient.getManufactures(carId) is ever called. Thought I might be missing a .subscribe some where but since this is being used by a webflux controller I think no #subscribes are needed anywhere
webSocketClient.getCars(dealerId)
return an emptyMono
? If yes,webSocketClient#getManufactures
is never called since the paramcarIds
in theflatMap
can be an empty list (notice thatFlux#collectList
emits an empty list if the sequence is empty). – Oarsman