I am new to reactive programming (Spring webflux) and wanted how to best handle this use case. I have a reactive service call (getAccount) that returns Mono and I want to chain it with another service call getBooks that returns Mono<Set> and one final synchronous call transform that perform some kind of transformation and returns something like Mono<Set> How would I chain and return the transformed data in the form of Mono<Set> while logging warnings when getAccount or getBooks are returning empty? Here is a simplified version of what I am trying to do as an example.
Given some fake services here
public static Mono<String> getAccount(String name){
return Mono.just(name);
}
public static Mono<Set<Book> getBooks(String title){
return Mono.just(Sets.newHashSet(new Book(title + "One", "Author One"),
new Book(title +"Two", "Author Two"),
new Book(title + "Three", "Author Three")));
}
public static LibraryBook transform (Book a){
return new LibraryBook(a.getTitle(), a.getAuthorName(), "someUniqueId");
}
I wanted to get the account of a given user and find all the books that he/she borrowed and transform the books and return the value as a Mono<Set> while logging warnings where appropriate
Here is my start
public Mono<Set<LibraryBook>> getBorrowedBooks(String userId) {
return getAccount(userId)
.flatMap(account -> getBooks(account))
.log()
.map(books -> books.stream().map(book -> transform(book)).collect(Collectors.toSet()))
}
However, I am not sure if mixing reactive and stream is a bad thing and it just does not look right.

