Java Spring WebFlux vs RxJava

Reactive programming is a programming paradigm, but I wouldn’t call it new. It’s actually been around for a while. Just like object-oriented programming, functional programming, or procedural programming, reactive programming is another programming paradigm. Paradigm is defined by Reactive Manifesto Reactive Streams, on the other hand, is a specification. For Java programmers, Reactive Streams is … Read more

Can I use SpringMvc and webflux together?

As explained in the Spring Boot reference documentation, Spring Boot will auto-configure a Spring MVC application if both MVC and WebFlux are available. There are several reasons for this: Spring MVC can’t run on Netty both infrastructure will compete for the same job (for example, serving static resources, the mappings, etc) mixing both runtime models … Read more

Threading model of Spring WebFlux and Reactor

After the question, the present documentation does provide some clues about the concurrency model and the threads one could expect (but I still think that clearer/better descriptions of what happens under-the-scene from a multi-threading perspective would be highly appreciated by Spring newcomers). It discusses the difference between Spring MVC and Spring WebFlux (1-thread-per-request model vs. … Read more

How to check if Mono is empty?

The techniques that allow checking whether Flux/Mono is empty Using operators .switchIfEmpty/.defaultIfEmpty/Mono.repeatWhenEmpty Using mentioned operators you will be able to react to the case when Stream has been completed without emitting any elements. First of all, remember that operators such .map, .flatMap, .filter and many others will not be invoked at all if there no … Read more

map vs flatMap in reactor

map is for synchronous, non-blocking, 1-to-1 transformations flatMap is for asynchronous (non-blocking) 1-to-N transformations The difference is visible in the method signature: map takes a Function<T, U> and returns a Flux<U> flatMap takes a Function<T, Publisher<V>> and returns a Flux<V> That’s the major hint: you can pass a Function<T, Publisher<V>> to a map, but it … Read more

How to log request and response bodies in Spring WebFlux

This is more or less similar to the situation in Spring MVC. In Spring MVC, you can use a AbstractRequestLoggingFilter filter and ContentCachingRequestWrapper and/or ContentCachingResponseWrapper. Many tradeoffs here: if you’d like to access servlet request attributes, you need to actually read and parse the request body logging the request body means buffering the request body, … Read more

what does Mono.defer() do?

It is a bit of an oversimplification but conceptually Reactor sources are either lazy or eager. More advanced ones, like an HTTP request, are expected to be lazily evaluated. On the other side the most simple ones like Mono.just or Flux.fromIterable are eager. By that, I mean that calling Mono.just(System.currentTimeMillis()) will immediately invoke the currentTimeMillis() … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)