Questions tagged [project-reactor]

Reactor is a foundational library building for reactive fast data applications on the JVM. It provides abstractions for Java, Groovy and other JVM languages to make building event and data-driven applications easier. It’s also really fast.

Reactor is a foundational library building for reactive fast data applications on the JVM. It provides abstractions for Java, Groovy and other JVM languages to make building event and data-driven applications easier. It’s also really fast.

3171 questions
129
votes
1 answer

Correct way of throwing exceptions with Reactor

I'm new to project Reactor and reactive programming in general. I'm currently working on a piece of code similar to this: Mono.just(userId) .map(repo::findById) .map(user-> { if(user == null){ throw new…
davioooh
  • 23,742
  • 39
  • 159
  • 250
100
votes
3 answers

Akka or Reactor

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…
David Riccitelli
  • 7,491
  • 5
  • 42
  • 56
77
votes
5 answers

Mono vs Flux in Reactive Stream

As per the documentation: Flux is a stream which can emit 0..N elements: Flux fl = Flux.just("a", "b", "c"); Mono is a stream of 0..1 elements: Mono mn = Mono.just("hello"); And as both are the implementations of the Publisher…
KayV
  • 12,987
  • 11
  • 98
  • 148
64
votes
4 answers

what does Mono.defer() do?

I've come across Mono.defer() in some Spring webflux code I looked up the method in the docs but don't understand the explanation: "Create a Mono provider that will supply a target Mono to subscribe to for each Subscriber downstream" please could I…
James Render
  • 1,490
  • 1
  • 14
  • 26
62
votes
2 answers

Mono switchIfEmpty() is always called

I have two methods. Main method: @PostMapping("/login") public Mono> loginUser(@RequestBody final LoginUser loginUser) { return socialService.verifyAccount(loginUser) .flatMap(socialAccountIsValid ->…
59
votes
2 answers

How do I use Reactor's StepVerifier to verify a Mono is empty?

I am using StepVerifier to test values: @Test public void testStuff() { Thing thing = new Thing(); Mono result = Mono.just(thing); StepVerifier.create(result).consumeNextWith(r -> { assertEquals(thing, r); …
Mark
  • 4,970
  • 5
  • 42
  • 66
59
votes
3 answers

map vs flatMap in reactor

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…
shredding
  • 5,374
  • 3
  • 46
  • 77
58
votes
5 answers

How to check if Mono is empty?

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:…
voliveira89
  • 1,134
  • 2
  • 9
  • 22
58
votes
12 answers

How to log request and response bodies in Spring WebFlux

I want to have centralised logging for requests and responses in my REST API on Spring WebFlux with Kotlin. So far I've tried this approaches @Bean fun apiRouter() = router { (accept(MediaType.APPLICATION_JSON) and "/api").nest { …
Koguro
  • 837
  • 4
  • 9
  • 10
56
votes
1 answer

Threading model of Spring WebFlux and Reactor

Currently experimenting reactive programming with Spring 5.0.0.RC2, Reactor 3.1.0.M2 and Spring Boot 2.0.0.M2. Wondering about the concurrency and threading model used by WebFlux and Reactor to properly code the application and handle the mutable…
55
votes
1 answer

Mono class in Java: what is, and when to use?

I have this following code: import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.BodyInserters; import…
S.I.M.P.L.E
  • 695
  • 1
  • 5
  • 10
52
votes
1 answer

Can I use SpringMvc and webflux together?

I would like to use 2 approaches(reactive and standard) in one project. I tried to migrate one REST API endpoint to reactive webflux and test performance before migrate rest of them. But it didn't work. I added router and handler for him, but until…
51
votes
3 answers

Java Spring WebFlux vs RxJava

I’m starting to learn reactive programming in Java. The whole reactive paradigm is new to me. In my learning process, i have come across few terms/libraries such as Spring WebFlux, projectreactor, and RxJava. I hope someone can explain what the…
51
votes
2 answers

Mono vs CompletableFuture

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…
XYZ
  • 709
  • 2
  • 9
  • 12
51
votes
4 answers

Convert from Flux to Mono

How can I convert from a Flux with 1 element to a Mono? Flux.fromArray(arrayOf(1,2,1,1,1,2)) .distinct() .take(1) How do I make this a Mono(1)?
Valahu
  • 763
  • 2
  • 8
  • 15
1
2 3
99 100