project-reactor

Is really necessary to use Hystrix with reactive spring boot 2 application?

巧了我就是萌 提交于 2019-12-21 06:18:53
问题 I'm working in a project in which we are moving some of ours microservices from Spring-MVC to Spring-Webflux to test the reactive paradigm. Looking for some help in the github repository of hystrix we've noted that the project have no commits since a year ago, and it's based in RxJava, so there are some incompatibilities with project-reactor. We're having some issues using Hystrix, particulary that the annotations from "Javanica" doesn't work and our developers need to use HystrixCommands

JDBC with Webflux - how to dispatch to container thread

…衆ロ難τιáo~ 提交于 2019-12-21 05:41:15
问题 I am working on a small proof-of-concept with webflux. In one part of my application I would like to communicate with a database (via JDBC) which is blocking and is not a good fit for reactor. Nevertheless for this proof-of-concept, I am thinking of following trick: Define a dedicated thread pool (let's call it DBThreadPool ) as ExecutorService with a fixed number of threads that equal JDBC connection pool size. Wrap that pool in Reactor Scheduler (named dbScheduller ) Wrap blocking call

Webflux websocketclient, How to send multiple requests in same session[design client library]

房东的猫 提交于 2019-12-20 18:46:19
问题 TL;DR; We are trying to design a WebSocket server using spring webflux WebSocket implementation. The server has usual HTTP server operations e.g. create/fetch/update/fetchall . Using WebSockets we were trying to expose one endpoint so the clients could leverage a single connection for all sort of operations, given WebSockets are meant for this purpose. Is it a right design with webflux and WebSockets? Long Version We are starting a project which is going to use reactive web sockets from

Webflux websocketclient, How to send multiple requests in same session[design client library]

天涯浪子 提交于 2019-12-20 18:46:11
问题 TL;DR; We are trying to design a WebSocket server using spring webflux WebSocket implementation. The server has usual HTTP server operations e.g. create/fetch/update/fetchall . Using WebSockets we were trying to expose one endpoint so the clients could leverage a single connection for all sort of operations, given WebSockets are meant for this purpose. Is it a right design with webflux and WebSockets? Long Version We are starting a project which is going to use reactive web sockets from

How to do sequence of operations and ensure one operation is complete before next one in Spring Reactor web app?

我的未来我决定 提交于 2019-12-20 11:28:40
问题 I have Spring Boot 2 web app in which I need to identify site visitor by cookie and gather page view stats. So I need to intercept every web request. The code I had to write is more complex than call back hell (the very problem Spring reactor was supposed to solve). Here is the code: package mypack.conf; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.UUID; import org.springframework.beans.factory.annotation.Autowired;

How to check if Mono is empty?

走远了吗. 提交于 2019-12-20 10:38:11
问题 I'm developing a app with Spring Boot 2.0 and Kotlin using the WebFlux framework. I want to check if a user id exits before save a transaction. I'm stucked in a simple thing like validate if a Mono is empty. fun createTransaction(serverRequest: ServerRequest) : Mono<ServerResponse> { val transaction = serverRequest.body(BodyExtractors.toMono(Transaction::class.java)) transaction.flatMap { val user = userRepository.findById(it.userId) // If it's empty, return badRequest() } return transaction

Mono vs CompletableFuture

孤人 提交于 2019-12-20 10:37:13
问题 CompletableFuture executes a task on a separate thread ( uses a thread-pool ) and provides a callback function. Let's say I have an API call in a CompletableFuture . Is that an API call blocking? Would the thread be blocked till it does not get a response from the API? ( I know main thread/tomcat thread will be non-blocking, but what about the thread on which CompletableFuture task is executing? ) Mono is completely non-blocking, as far as I know. Please shed some light on this and correct me

Web Reactive Programming - What are the advantages from the HTTP client point of view?

孤人 提交于 2019-12-20 10:33:34
问题 Lets suppose these two scenarios of a controller that generates some random numbers with a delay: 1) Reactive Spring 5 reactive application: @GetMapping("/randomNumbers") public Flux<Double> getReactiveRandomNumbers() { return generateRandomNumbers(10, 500); } /** * Non-blocking randon number generator * @param amount - # of numbers to generate * @param delay - delay between each number generation in milliseconds * @return */ public Flux<Double> generateRandomNumbers(int amount, int delay){

Spring WebFlux: Only one connection receive subscriber allowed

梦想与她 提交于 2019-12-19 21:49:08
问题 I am writing a simple app with Spring 5 Webflux and Kotlin. I am trying to implement PUT endpoint in a following way: PUT("/confs/{id}", { val id = it.pathVariable("id") ServerResponse.ok().body(service.save(it.bodyToMono(Item::class.java)), Item::class.java) }) The trick on save is that I try to read a city name from item, resolve geo coordinates, overwrite them in original item and then save to Mongo using Spring Data Mongo Reactive repo. fun save(item: Mono<Item>): Mono<Item> { val geo =

How to limit the request/second with WebClient?

左心房为你撑大大i 提交于 2019-12-19 09:05:38
问题 I'm using a WebClient object to send Http Post request to a server. It's sending a huge amount of requests quite rapidly (there is about 4000 messages in a QueueChannel ). The problem is... it seems the server can't respond fast enough... so I'm getting a lot of server error 500 and connexion closed prematurely. Is there a way to limit the number of request per seconds ? Or limit the number of threads it's using ? EDIT : The Message endpoint processe message in a QueueChannel :