Questions tagged [spring-webflux]

Spring Framework 5 includes a new spring-webflux module. The module contains support for reactive HTTP and WebSocket clients as well as for reactive server web applications including REST, HTML browser, and WebSocket style interactions. WebFlux can run on Servlet containers with support for the Servlet 3.1 non-blocking I/O API as well as on other async runtimes such as Netty and Undertow.

Questions tagged spring-webflux should be about applications using the Spring WebFlux framework.

If Spring Boot is involved, please also tag the question with spring-boot. If the question is related to the use of Reactor operators, please tag the question with project-reactor as well.

For Spring WebFlux related documentation, please refer to the:

6050 questions
23
votes
2 answers

Spring WebFlux, how can I debug my WebClient POST exchange?

I am having trouble understanding what I've done wrong in constructing my WebClient request. I would like to understand what the actual HTTP request looks like. (e.g., dumping the raw request to console) POST /rest/json/send HTTP/1.1 Host:…
nograde
  • 2,268
  • 5
  • 22
  • 29
23
votes
5 answers

WebExceptionHandler : How to write a body with Spring Webflux

I want to handle the Exception of my api by adding a WebExceptionHandler. I can change the status code, but I am stuck when i want to change the body of the response : ex adding the exception message or a custom object. Does anyone have exemple…
adrien le roy
  • 823
  • 2
  • 7
  • 12
23
votes
1 answer

How to get the context of the current request in spring-webflux

In the classic spring-mvc it is possible to set request scoped attributes on a RequestContextHolder. Building on that, we can parse an incoming request in a HandlerInterceptorAdapter, set request parameters such as currently logged in user, unique…
Doron Gold
  • 3,664
  • 4
  • 32
  • 44
22
votes
2 answers

PrematureCloseException: Connection prematurely closed

im using Web-flux/Reactive and Webclient, running it on tomcat and spring-boot. Everything works fine. I read a lot about it. The problem seems to be that whenever you use webclient, you have to return or use the response, otherwise it will close…
Douglas Santos
  • 515
  • 1
  • 4
  • 12
22
votes
1 answer

Is there a difference between doOnSuccess vs doOnNext for a Mono?

Let's say you have Mono someIntegerSource = Mono.just(5) and you want to assign it to a variable. Is there a difference between these code snippets? Case 1: doOnSuccess someIntegerSource.doOnSuccess(number -> this.myNumber = number) Case…
CowZow
  • 1,275
  • 2
  • 17
  • 36
22
votes
1 answer

Conditional repeat or retry on Mono with webclient from Spring WebFlux

I want implement a conditional repeat on a Mono in WebFlux with WebClient. The situation is the following: We have a rest service service that returns a generated document. The generation of this document is triggered from another service that gets…
Bernado
  • 548
  • 1
  • 6
  • 18
22
votes
1 answer

Spring 5 WebFlux Mono and Flux

In Spring 5 I just know Spring WebFlux Handler method handles the request and returns Mono or Flux as response. @Component public class HelloWorldHandler { public Mono helloWorld(ServerRequest request) { return…
Shalika
  • 1,457
  • 2
  • 19
  • 38
22
votes
3 answers

Adding a retry all requests of WebClient

we have a server to retrieve a OAUTH token, and the oauth token is added to each request via WebClient.filter method e.g webClient .mutate() .filter((request, next) -> tokenProvider.getBearerToken() …
Kevin Hussey
  • 1,582
  • 1
  • 10
  • 17
22
votes
7 answers

what is the right way to handle errors in spring-webflux

I've been doing some research using spring-webflux and I like to understand what should be the right way to handle errors using Router Functions. I've created an small project to test a couple of scenarios, and I like to get feedback about it, and…
Juan Medina
  • 533
  • 1
  • 5
  • 12
21
votes
5 answers

How to perform an action only if the Mono is empty and throw an error if not empty

I'm trying to convert a project to use Spring WebFlux and am running into a problem getting some basic business logic working. I have a repository layer that is responsible for retrieving / persisting records and a service layer that is responsible…
cgaskill
  • 411
  • 1
  • 3
  • 7
21
votes
2 answers

Does Spring Transaction Management Work with Spring WebFlux?

Does Spring's support for RDBMS transaction management also work in Spring WebFlux? For example, assuming proper configuration, will a method annotated with the @Transactional annotation use the Spring transaction manager and rollback the…
user3303372
  • 761
  • 1
  • 10
  • 21
21
votes
2 answers

How to collect paginated API responses using spring boot WebClient?

I have a paginated response from an URL, I want to keep on hitting the next page URL which I get from the previous response and keep on collecting items till I don't have a "nextPage" URL in my response. How to achieve this in a reactive way using…
21
votes
2 answers

Don't spring-boot-starter-web and spring-boot-starter-webflux work together?

When I start to learn the spring-webflux, I have the question about this component. I built a simple project, using maven to manage it. I addded the dependencies related to spring-boot-starter-web and spring-boot-starter-webflux, like : …
kenzhaoyihui
  • 213
  • 1
  • 2
  • 4
21
votes
4 answers

WebFlux functional: How to detect an empty Flux and return 404?

I'm having the following simplified handler function (Spring WebFlux and the functional API using Kotlin). However, I need a hint how to detect an empty Flux and then use noContent() for 404, when the Flux is empty. fun findByLastname(request:…
20
votes
1 answer

Should we use a reactive-stack web framework like spring webflux when we have blocking calls?

I'm trying to understand when we would use a reactive-stack framework like webflux. I've read articles that seems to suggest that we would benefit from reactive approach when we have many blocking calls. For example, if we had a webhook service that…
pcatre
  • 1,304
  • 2
  • 16
  • 24