project-reactor

Project Reactor. Mono.map() vs Mono.flatMap()

不羁的心 提交于 2020-08-27 07:10:11
问题 What is the principal difference between these in terms of Mono ? From the documentation, I read that flatMap acts asynchronous and map synchronous. But that doesn't really make sense for me b/c Mono is all about parallelism and that point isn't understandable. Can someone rephrase it in a more understandable way? Then in the documentation for flatMap stated (https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Mono.html#flatMap-java.util.function.Function-): Transform the

How to emit cumulative sum only from a reactive stream?

孤街浪徒 提交于 2020-08-10 19:57:27
问题 I've a use case where the stream should only emit when the cumulative "sum" equals or exceeds a given value, n. Let's take the example of six integers with n = 5. +---+------+---------+ | i | Emit | Sum | +---+------+---------+ | 1 | - | 1 | | 2 | - | 3 | | 3 | 5 | 1 | | 4 | 5 | 0 | | 5 | 5 | 0 | | 2 | 2 | 0 (end) | +---+------+---------+ As you can see, nothing is emitted unless the sum equals or exceeds 5, except for the last element, which is emitted anyway. Once an item is emitted, the

Spring WebFlux (reactor). Error when zipWith - Could not emit tick due to lack of requests

天涯浪子 提交于 2020-08-08 09:40:32
问题 I have a Flux, for each object I should make an API call to the third party REST (about 1000 calls). To prevent to many requests per second Im using: Flux<Calls> callsIntervalFlux= Flux.interval(Duration.ofMillis(100)) .zipWith(callsFlux, (i, call) -> call); // and now Calls emits every 10ms, and REST API is not overloaded The problem is, sometimes application fails with exception: reactor.core.Exceptions$ErrorCallbackNotImplemented: reactor.core.Exceptions$OverflowException: Could not emit

Spring WebFlux (reactor). Error when zipWith - Could not emit tick due to lack of requests

心不动则不痛 提交于 2020-08-08 09:39:41
问题 I have a Flux, for each object I should make an API call to the third party REST (about 1000 calls). To prevent to many requests per second Im using: Flux<Calls> callsIntervalFlux= Flux.interval(Duration.ofMillis(100)) .zipWith(callsFlux, (i, call) -> call); // and now Calls emits every 10ms, and REST API is not overloaded The problem is, sometimes application fails with exception: reactor.core.Exceptions$ErrorCallbackNotImplemented: reactor.core.Exceptions$OverflowException: Could not emit

Execute blocking JDBC call in Spring Webflux

假装没事ソ 提交于 2020-08-04 05:13:58
问题 I am using Spring Webflux with Spring data jpa using PostgreSql as backend db. I don't want to block the main thread while making db calls like find and save . To achieve the same, I have a main scheduler in Controller class and a jdbcScheduler service classes. The way I have defined them is: @Configuration @EnableJpaAuditing public class CommonConfig { @Value("${spring.datasource.hikari.maximum-pool-size}") int connectionPoolSize; @Bean public Scheduler scheduler() { return Schedulers

Spring WebClient: How to stream large byte[] to file?

时光毁灭记忆、已成空白 提交于 2020-07-31 12:13:49
问题 It seems like it the Spring RestTemplate isn't able to stream a response directly to file without buffering it all in memory. What is the proper to achieve this using the newer Spring 5 WebClient ? WebClient client = WebClient.create("https://example.com"); client.get().uri(".../{name}", name).accept(MediaType.APPLICATION_OCTET_STREAM) ....? I see people have found a few workarounds/hacks to this issue with RestTemplate , but I am more interested in doing it the proper way with the WebClient

Spring WebClient: How to stream large byte[] to file?

人盡茶涼 提交于 2020-07-31 12:13:28
问题 It seems like it the Spring RestTemplate isn't able to stream a response directly to file without buffering it all in memory. What is the proper to achieve this using the newer Spring 5 WebClient ? WebClient client = WebClient.create("https://example.com"); client.get().uri(".../{name}", name).accept(MediaType.APPLICATION_OCTET_STREAM) ....? I see people have found a few workarounds/hacks to this issue with RestTemplate , but I am more interested in doing it the proper way with the WebClient