project-reactor

The difference between onErrorResume and doOnError

核能气质少年 提交于 2020-12-29 12:06:51
问题 In spring project reactor, what are the differences between onErrorResume and doOnError ? and when I should each of them ? 回答1: onErrorResume : Gives a fallback stream when some exception occurs happens in the upstream. doOnError : Side-effect operator. Suppose you want to log what error happens in the upstream. Example: Mono.just(request) .flatMap(this::makeHTTPGet) .doOnError(err -> { log.error("Some error occurred while making the POST call",err) }) .onErrorResume(err -> Mono.just

The difference between onErrorResume and doOnError

筅森魡賤 提交于 2020-12-29 12:06:33
问题 In spring project reactor, what are the differences between onErrorResume and doOnError ? and when I should each of them ? 回答1: onErrorResume : Gives a fallback stream when some exception occurs happens in the upstream. doOnError : Side-effect operator. Suppose you want to log what error happens in the upstream. Example: Mono.just(request) .flatMap(this::makeHTTPGet) .doOnError(err -> { log.error("Some error occurred while making the POST call",err) }) .onErrorResume(err -> Mono.just

Mono.Defer() vs Mono.create() vs Mono.just()?

限于喜欢 提交于 2020-12-29 03:54:43
问题 Could someone help me to understand the difference between Mono.defer(), Mono.create() and Mono.just()? How to use it properly? 回答1: Mono.just(value) is the most primitive - once you have a value you can wrap it into a Mono and subscribers down the line will get it. Mono.defer(monoSupplier) lets you provide the whole expression that supplies the resulting Mono instance. The evaluation of this expression is deferred until somebody subscribes. Inside of this expression you can additionally use

Spring boot with WebFlux always throw 403 status in tests

不问归期 提交于 2020-12-05 11:54:10
问题 Great thx for viewing my question) I have some strange subject: my spring boot tests don't work. They start successfully but always throwing 403 HTTP status when making the requests to any controller I have some project with next dependencies: buildscript { ext.kotlin_version = '1.3.71' dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.71" classpath "org.springframework.boot:spring-boot-gradle-plugin:2.2.1.RELEASE" classpath "com.google.cloud.tools.jib:com.google.cloud

Spring boot with WebFlux always throw 403 status in tests

妖精的绣舞 提交于 2020-12-05 11:48:25
问题 Great thx for viewing my question) I have some strange subject: my spring boot tests don't work. They start successfully but always throwing 403 HTTP status when making the requests to any controller I have some project with next dependencies: buildscript { ext.kotlin_version = '1.3.71' dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.71" classpath "org.springframework.boot:spring-boot-gradle-plugin:2.2.1.RELEASE" classpath "com.google.cloud.tools.jib:com.google.cloud

Project Reactor, using a Flux sink outside of the creation lambda

我的未来我决定 提交于 2020-12-03 05:35:07
问题 When my service starts up, I want to construct a simple pipeline. I'd like to isolate the Flux sink, or a Processor, to emit events with. Events will be coming in from multiple threads and should be processed according to the pipeline's subscribeOn() specification, but everything seems to run on the main thread. What is the best approach? I've attached my attempts below. (I'm using reactor-core v3.2.8.RELEASE.) import org.junit.jupiter.api.Test; import reactor.core.publisher.DirectProcessor;

Project Reactor, using a Flux sink outside of the creation lambda

夙愿已清 提交于 2020-12-03 05:27:22
问题 When my service starts up, I want to construct a simple pipeline. I'd like to isolate the Flux sink, or a Processor, to emit events with. Events will be coming in from multiple threads and should be processed according to the pipeline's subscribeOn() specification, but everything seems to run on the main thread. What is the best approach? I've attached my attempts below. (I'm using reactor-core v3.2.8.RELEASE.) import org.junit.jupiter.api.Test; import reactor.core.publisher.DirectProcessor;

How to calculate the average of a Project Reactor Flux?

早过忘川 提交于 2020-11-30 00:11:45
问题 I have a method that returns a Flux<SensorData> , let's suppose SensorData has a field measure: Integer . I would like to calculate the average value of measure of the whole Flux. How can it be done? val sensorFlux: Flux<SensorData> = sensorRepository.findAll() ... 回答1: Mono<Double> average = sensorFlux.collect(Collectors.averagingInt(SensorData::getMeasure)) 回答2: Another way of doing it with an auxiliary object: val average = sensorFlux.map { it.measure } .map { Measure(1, it) } .reduce { t: