I wonder how to write non-blocking code with Webflux.
Here is what I want to do:
ProductProperties
field (returned as Flux)Flux<Product>.availabilityCalendar
Use the data retrieved in step 2 and fetch some other data (returned as Flux<>) - everything should be a non-blocking operations. How to do that? How to get values from Flux<Object>
and then fetch some other data returned as Flux<> avoiding blocking operations like Flux.block() to retrieve data that are needed in the next step to fetch final data to return?
public Flux<Product> getAllProductsByAvailability(Flux<ProductProperties> productProperties,
Map<String, String> searchParams) {
productProperties
.flatMap(property -> productRepository.findByProductPropertiesId(property.getId())) //1. return Products
.flatMap(product -> Flux.just(product.getAvailabilityCalendar())) //2. how to get Product.availabilityCalendar list as non-blocking operation to work with this data afterwards?
(...)
where:
productRepository.findByProductPropertiesId
returns Flux
Product has field: ArrayList<ProductAvailability> availabilityCalendar
Is it a good approach?
Thank you!
by using the onNext parameter
productRepository.findByProductPropertiesId(property.getId())
.onNext(product -> {
return // Do things here
})
like this I check the tag valid
Flux.fromIterable(vo.getTags())
.flatMap((tag) -> tagService.findByCode(tag.getCode()).map(TagBo::createByVo)).filter(Objects::nonNull).collectList().doOnNext(l->vo.setTags(l));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.