I am working to introduce reactive programming to my company. I'm in the process of building a simple demo of an activity recommendation system to prove the performance benefits.
One of the challenges I have come up against is enriching the results in one stream with the results of another. I have a working example which is shown below but I am not sure if there are any issues with this approach. Could somebody take a look and provide any potential improvements.
public Flux<Integer> getRecommendedActivities(Long userId, String location, Integer limit) {
Flux<ActivityData> activities = activityDatabaseService.getByLocation(location);
Mono<Map<String,BigInteger>> userCategoryScores = userScoresDatabaseService.get(userId);
return activities
.zipWith(userCategoryScores.cache().repeat(), this::scoreActivitiesBasedOnUserCategoryScores)
.sort(compareActivityScoreStrength)
.map(ScoredActivityData::getActivityId)
.take(limit);
}
private ScoredActivityData scoreActivitiesBasedOnUserCategoryScores(ActivityData deal,Map<String, BigInteger> categoryScores){
//This method combines the deal score and user category scores to come up with a final score
}
Thanks, Carl