Reputation: 333
I'm practicing Reactor in Spring WebFlux and I find the learning curve quite steep. All I wanted to do is something like:
Data coming from the Controller I do a query for the site settings which returns a Mono. I do a query for the user repository (to later find out if the user was already registered or not) which returns a Mono.
Now I want to do something like:
User user = new User();
userRepository.findByUsername(username).flatMap(dbUser -> Mono.error(new UserAlreadyRegisteredException()).switchOnEmpty(settingsRepository.getSettings().flatMap(settings -> validateUser(user,incomingData,settings)).then(userRepository.save(user));
//validateUser is a method which returns Mono<User> preferably with incomingData copied to the User object
Edit: the problem was that I was persisting the Settings in a @PostConstruct and I didn't call subscribe.
Upvotes: 1
Views: 1834
Reputation: 2228
Go through the following links:
I went through this tutorial when I started with it: https://tech.io/playgrounds/929/reactive-programming-with-reactor-3/Intro
There's this video, https://youtu.be/Cj4foJzPF80, where Brian Clozel and Sebastien go through all those problems mentioned in the tech.io tutorial. Both of these were quite sufficient for me to start off. Start the tutorial, read the documentation (helped me a lot) and if stuck then go to the video for help. However you should see the starting of the video where they explain the concepts.
Go through these, and then let us know if you still have problems.
Upvotes: 1