spring-webflux

How to set and handle timeout in Spring WebClient?

孤者浪人 提交于 2019-12-23 00:49:19
问题 Spring docs says it is required to configure http client for WebClient manually to set timeouts: https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-client-builder-reactor-timeout. But since WebClient returns reactive Mono, it's possible (api-wise) to apply .timeout method. Does it have the same effect? Moreover, when one uses .timeout method, Reactor's TimeoutException is expected. Will the same error appear in the stream if configuration is done

H2 db not accessible at localhost:8080/h2-console when using webflux

我是研究僧i 提交于 2019-12-22 18:25:09
问题 H2 db is not accessible at localhost:8080/h2-console when using webflux. I read somewhere that this is available only when developing a Servlet based application. But I am using Webflux with Netty. So is there a way to see the h2 console in such an application? 回答1: I had the same issue, I ended up booting the console server manually on another port: @Component @Profile("test") // <-- up to you public class H2 { private org.h2.tools.Server webServer; private org.h2.tools.Server server;

Should I rely on “mono of item” or “plain item” arguments when composing reactive chains?

自作多情 提交于 2019-12-22 17:24:21
问题 I am have two versions of a Webflux/Reactor handler class. This class mimics a user sign up use case - as far as the business logic is concerned. The first version of the class relies upon a Mono<User> whereas the second version uses a plain User . First version of the class : this is the version relying on a Mono<User> argument down the chain. Notice the top level public method createUser uses a userMono . @Component @RequiredArgsConstructor public class UserHandler { private final @NonNull

Should I rely on “mono of item” or “plain item” arguments when composing reactive chains?

ぐ巨炮叔叔 提交于 2019-12-22 17:22:56
问题 I am have two versions of a Webflux/Reactor handler class. This class mimics a user sign up use case - as far as the business logic is concerned. The first version of the class relies upon a Mono<User> whereas the second version uses a plain User . First version of the class : this is the version relying on a Mono<User> argument down the chain. Notice the top level public method createUser uses a userMono . @Component @RequiredArgsConstructor public class UserHandler { private final @NonNull

Convert writes to OutputStream into a Flux<DataBuffer> usable by ServerResponse

﹥>﹥吖頭↗ 提交于 2019-12-22 12:22:50
问题 I have a legacy library that I have to use to retrieve a file. This legacy library doesn't return in InputStream, as you usually expect for reading stuff, but it expects that it is passed an open OutputStream, that it can write to. I have to write a Webflux REST service, that writes this OutputStream to the org.springframework.web.reactive.function.server.ServerResponse body. legacyLib.BlobRead(outputStream); // writes the stream to an outputstream, that has to be provided by me, and somehow

Default number of threads in Spring boot 2.0 reactive webflux configuration

风格不统一 提交于 2019-12-22 11:10:00
问题 While using Spring 5 reactive webflux with Spring boot 2.0, what's the default number of threads used to handle requests? How can I configure the number of threads used? 回答1: The default number of threads for request handling is determined by the underlying web server; by default, Spring Boot 2.0 is using Reactor Netty, which is using Netty's defaults (check out the EventLoopGroup documentation for that). Spring Boot will soon allow you to customize that part (see #10418). In the meantime,

Default number of threads in Spring boot 2.0 reactive webflux configuration

99封情书 提交于 2019-12-22 11:07:04
问题 While using Spring 5 reactive webflux with Spring boot 2.0, what's the default number of threads used to handle requests? How can I configure the number of threads used? 回答1: The default number of threads for request handling is determined by the underlying web server; by default, Spring Boot 2.0 is using Reactor Netty, which is using Netty's defaults (check out the EventLoopGroup documentation for that). Spring Boot will soon allow you to customize that part (see #10418). In the meantime,

Exception Handling Reactive

梦想与她 提交于 2019-12-22 08:24:22
问题 How does one use a Mono.error(<Throwable>) but attach information from the body returned from a request? Is there a reactive object that extends Throwable that takes a Mono/Flux object, so the error being thrown will wait for the body to be accounted for? Or is there a way to add some sort of 'flag' onto an existing Mono object to make it fail instantly (to circumvent the requirement to be Throwable ) Example scenario below: import org.springframework.web.reactive.function.client.WebClient;

how to wait for all requests to complete with Spring 5 WebClient?

◇◆丶佛笑我妖孽 提交于 2019-12-22 08:24:19
问题 I have a simple Java program that sends multiple requests with Spring WebClient. Each returns a mono, and I am using response.subscribe() to check the result. However, my main thread of execution finishes before all requests are processed, unless I add a long Thread.sleep(). With CompletableFutures you can use: CompletableFuture.allOf(futures).join(); Is there a way to wait for all Mono's to complete ? 回答1: As explained in the Project Reactor documentation, nothing happens until you subscribe

Does not the spring-boot-starter-web and spring-boot-starter-webflux work together?

牧云@^-^@ 提交于 2019-12-22 08:12:30
问题 When I start to learn the spring-webflux, I have the question about this component. I builded the simple project, useing the maven to manage the project, and add the dependences about spring-boot-starter-web and spring-boot-starter-webflux", like : <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> But