last day (15 days later) » 

4:11 PM
0
A: How to iterate over Flux and use result from another Mono to filter the Flux

uneq95Flux<MyObj2> filteredInfo = mono1.flatMapMany(myObj1 -> availabilityInfo.filter(myObj1 -> myObj1.getX() && myObj2.getY())); flatMapMany is used to create a flux by processing a mono. filter takes a predicate, which forms the basis of filtering the flux. Exa...

 
Don't we need to subscribe to inner flux by flatMap. I tried that but Mono return before flux emits response (WebClient call).
 
You can subscribe the filteredInfo Flux at the last if you wanna do something with it.
@akreddy.21 can you clearly specify what you are doing code wise? I have also put an example code for you to visualize things.
 
Pretty much the same what you specified in the example only extra thing is as soon as I find 3 I can return I don't need to process remaining flux elements.
Is there any way to contact you so I can show exactly what I am trying to do. That will be helpful
 
So, you want the first element which matches the criteria, right?
 
4:12 PM
hey
 
Thanks man for your time
 
no problem
 
Mono<SourceCodeInfo> sourceCodeInfo = sourceCodeRepository.get(apiRequest.getSourceCode());

//step: 1
// call florist-availability-service to get available florists for requested criteria
Flux<AvailabilityInfoResponse> availabilityInfo = getAvailabilityInfo(siteId,
FloristSelectionUtil.getProductId(apiRequest.getProduct()),
FloristSelectionUtil.getProductPrice(apiRequest.getProduct()),
FloristSelectionUtil.getZipCode(apiRequest.getRecipient()),
apiRequest.getDeliveryDate(),
apiRequest.getDeliveryDateEnd(),
sourceCodeInfo -- from mongo db
availabilityInfo -- from webclient call
Now i have to filter these flux using mono response and flux element
 
yes, i understand
So, you want the first element which matches the criteria, right?
 
Yes
 
4:15 PM
and you wanna neglect the others
?
 
Yes
 
So, finally should you get a Mono<Obj2>
?
 
Yes it is mono
I tried as below
But since one is Mono and other is flux it got cancelled
 
you can apply .take(1) to the final flux which will give you a flux with the very first element matching the criteria. but it will be a flux
@akreddy.21 What did you try?
 
return Flux.zip(info, availableInfo)
.flatMap(data -> {
if (data.getT1().getX() && data.getT2().getList.size() == 1) {
return Mono.just(ApiResponse.builder()
.deliveryDate(data.getT2().getDeliveryDate())
.selectedMember(data.getT2().getList().get(0))
.build());
}
return Mono.empty();
}).next().log()
 
4:21 PM
just wait for a couple of minutes . let me check the docs. I think there could be a better way.
 
If I process entire flux elements, Iniside the if conditions there are two more IO calls to decide the final solution. I end up calling so many IO calls though first match is sufficient enough for me
Okay
 
the best I can see for the time being is this
Mono<Integer> res = mono.flatMapMany(i -> flux.filter(j -> j % i == 0).take(1)).single();
 
I tried the same. I didn't do any subscribe() in code. I can see that flux and Mono calls are trigerred from logs but still I got empty response.
 
flux.collectList().zipWith(mono).flatMap(tuple -> {
List<Integer> list = tuple.getT1();
int x = tuple.getT2();
for(int y:list){
if(y%x==0){
return Mono.just(x);
}
}
return Mono.empty();
}).subscribe(System.out::println);
This is another approach
can you try this
?
 
4:48 PM
Tried , empty response seems the flux is not happening. I will also try some other ways to do this.
 
did you try the latest approach which i suggested?
 
is it advisable to use .toStream() on list and convert it to List and do the logic. I am afraid that I am lossing reactive benefits If I use .toStream()
Yes I tried with latest approach
 
you can do it unless you use the block() call on a flux or mono
If you tried the latest approach, then I think any element isn't satisfying the criteria
 
There are elements with criteria.
 
Are you sure they are coming in your availability flux? did you log it and see?
 
4:55 PM
Yes. I am able to see them. It is always going to Mono.empty()
I tried with .zip() also
 
can you share your screen?
teamviewer?
 
Yes.. Don't know whether I can share the Id here in this channel
 
why not?
 
1 121 299 545
 
pwd?
 
5:00 PM
g7r3w8
 
oops i need a newer version
 
mine is 14
 
i have lower version
 
skype?
 
wait i am updating it
same partner id?
pwd
 
5:07 PM
Yes
 

last day (15 days later) »