How to make reactive webclient follow 3XX-redirects?
You need to configure the client per the docs WebClient.builder() .clientConnector(new ReactorClientHttpConnector( HttpClient.create().followRedirect(true) ))
You need to configure the client per the docs WebClient.builder() .clientConnector(new ReactorClientHttpConnector( HttpClient.create().followRedirect(true) ))
flatMap vs flatMapMany In functional programming, flatMap returns the same type than the type that bear the method, so for Mono<T>, flatMap returns a Mono. Which means that only one element can be emitted by the inner Publisher (or that it is truncated). We enforced that by having Mono#flatMap take a Function<T, Mono<R>>. As a … Read more
First, a few things that will help you understand the code snippet solving this use case. You should never call a blocking method within a method that returns a reactive type; you will block one of the few threads of your application and it is very bad for the application Anyway as of Reactor 3.2, … Read more
It’s because switchIfEmpty accepts Mono “by value”. Meaning that even before you subscribe to your mono, this alternative mono’s evaluation is already triggered. Imagine a method like this: Mono<String> asyncAlternative() { return Mono.fromFuture(CompletableFuture.supplyAsync(() -> { System.out.println(“Hi there”); return “Alternative”; })); } If you define your code like this: Mono<String> result = Mono.just(“Some payload”).switchIfEmpty(asyncAlternative()); It’ll always … Read more
In Reactor 3, the from operator has been specialized into a few variants, depending on the original source (array, iterable, etc…). Use yourMono.flatMapMany(Flux::fromIterable) in your case.
I’m not sure I can adequately answer your question in this small space. But I’ll give it a shot! 🙂 Spring’s ApplicationEvent system and Reactor are really quite distinct as far as functionality goes. ApplicationEvent routing is based on the type handled by the ApplicationListener. Anything more complicated than that and you’ll have to implement … Read more
Well, Reactive Programming means you are doing all your IO bound tasks such as network calls asynchronously. For an instance say your application calls an external REST API or a database, you can do that invocation asynchronously. If you do so your current thread does not block. You can serve lots of requests by merely … Read more
Instead of take(1), you could use next(). This will transform the Flux into a valued Mono by taking the first emitted item, or an empty Mono if the Flux is empty itself.
This is really not as complicated as other answers imply. The only way to stream the data without buffering it all in memory is to use a pipe, as @jin-kwon suggested. However, it can be done very simply by using Spring’s BodyExtractors and DataBufferUtils utility classes. Example: private InputStream readAsInputStream(String url) throws IOException { PipedOutputStream … Read more
CompletableFuture is Async. But is it non-blocking? One which is true about CompletableFuture is that it is truly async, it allows you to run your task asynchronously from the caller thread and the API such as thenXXX allows you to process the result when it becomes available. On the other hand, CompletableFuture is not always … Read more