project-reactor

Adding a retry all requests of WebClient

大兔子大兔子 提交于 2019-12-03 15:10:09
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() .map(token -> ClientRequest.from(request) .headers(httpHeaders -> httpHeaders.set("Bearer", token)) .build()).flatMap(next::exchange)) .build(); TokenProvider.getBearerToken returns Mono<String> since it is a webclient request (this is cached) I want to have a retry functionality that on 401 error, will invalidate the token and try the request again I have this working like so webClient.post() .uri

map vs flatMap in reactor

南笙酒味 提交于 2019-12-03 12:02:48
问题 I've found a lot of answers regarding RxJava, but I want to understand how it works in Reactor. My current understanding is very vague, i tend to think of map as being synchronous and flatMap to be asynchronous but I can't really get my had around it. Here is an example: files.flatMap { it -> Mono.just(Paths.get(UPLOAD_ROOT, it.filename()).toFile()) .map {destFile -> destFile.createNewFile() destFile } .flatMap(it::transferTo) }.then() I have files (a Flux<FilePart> ) and i want to copy it to

Mono vs CompletableFuture

主宰稳场 提交于 2019-12-03 07:58:16
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 if I am wrong. CompletableFuture is Async. But is it non-blocking? One which is true about

Difference Between Flux.create and Flux.generate

半世苍凉 提交于 2019-12-03 07:26:44
问题 What is the difference between Flux.create and Flux.generate? I am looking--ideally with an example use case--to understand when I should use one or the other. 回答1: In short: Flux::create doesn't react to changes in the state of the app while Flux::generate does. The long version Flux::create You will use it when you want to calculate multiple (0...infinity) values which are not influenced by the state of your app and the state of your pipeline (your pipeline == the chain of operations which

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

折月煮酒 提交于 2019-12-03 07:09:58
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 spring-webflux . We need to build a reactive client library which can be used by consumers to connect to the

Benefits of having HTTP endpoints return Flux/Mono instances instead of DTOs [closed]

天大地大妈咪最大 提交于 2019-12-03 03:43:52
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 11 months ago . I've watched Spring Tips: Functional Reactive Endpoints with Spring Framework 5.0 and read a little about spring reactor but I can't quite understand it. What are the benefits of having endpoints return Flux / Mono instances (jacksonified) instead of straight up dto objects

Comparison of Java reactive frameworks [closed]

限于喜欢 提交于 2019-12-03 03:37:57
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . I see many frameworks/libraries that claim that they can help build reactive applications in Java, such as: Akka, Vert.x, RxJava, Reactor, QBit, etc. They seem to have different approaches, features, pros, cons, etc. I could not find detailled comparisons. There is

map vs flatMap in reactor

烈酒焚心 提交于 2019-12-03 02:42:42
I've found a lot of answers regarding RxJava , but I want to understand how it works in Reactor. My current understanding is very vague, i tend to think of map as being synchronous and flatMap to be asynchronous but I can't really get my had around it. Here is an example: files.flatMap { it -> Mono.just(Paths.get(UPLOAD_ROOT, it.filename()).toFile()) .map {destFile -> destFile.createNewFile() destFile } .flatMap(it::transferTo) }.then() I have files (a Flux<FilePart> ) and i want to copy it to some UPLOAD_ROOT on the server. This example is taken from a book. I can change all the .map to

Akka or Reactor [closed]

梦想与她 提交于 2019-12-03 01:32:03
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . I am in the process of starting a new project (java-based). I need to build it as a modular, distributed and resilient architecture. Therefore I would like to have the business processes to communicate among themselves, be interoperable, but also independent. I am looking

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

左心房为你撑大大i 提交于 2019-12-03 01:30:47
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; import org.springframework.beans.factory.annotation.Value; import org.springframework.context