project-reactor

Issue with Spring Webflux webclient , nothing happens when trying to send post request

拜拜、爱过 提交于 2021-01-27 07:00:37
问题 Have the following implementation of webclient : public <T> WebClient.ResponseSpec sendRequest(HttpMethod method, String contentType, T body, String baseUrl, String path) { try { WebClient webClient = WebClient.builder().baseUrl(baseUrl).filter(logRequest()).build(); WebClient.ResponseSpec responseSpec = webClient.method(method) .uri(path) .header(HttpHeaders.CONTENT_TYPE, contentType) .body(BodyInserters.fromObject(body)) .retrieve(); return responseSpec; } catch (Exception e) { throw new

Issue with Spring Webflux webclient , nothing happens when trying to send post request

大憨熊 提交于 2021-01-27 06:55:52
问题 Have the following implementation of webclient : public <T> WebClient.ResponseSpec sendRequest(HttpMethod method, String contentType, T body, String baseUrl, String path) { try { WebClient webClient = WebClient.builder().baseUrl(baseUrl).filter(logRequest()).build(); WebClient.ResponseSpec responseSpec = webClient.method(method) .uri(path) .header(HttpHeaders.CONTENT_TYPE, contentType) .body(BodyInserters.fromObject(body)) .retrieve(); return responseSpec; } catch (Exception e) { throw new

Is it safe to use the same FluxSink from multiple threads concurrently

我怕爱的太早我们不能终老 提交于 2021-01-24 11:36:10
问题 I know a Publisher must not publish concurrently, but if I use Flux#create(FluxSink) , can I safely call FluxSink#next concurrently? In other words, does Spring have internal magic that ensures proper serial publishing of events even if FluxSink#next is called concurrently? public class FluxTest { private final Map<String, FluxSink<Item>> sinks = new ConcurrentHashMap<>(); // Store a new sink for the given ID public void start(String id) { Flux.create(sink -> sinks.put(id, sink)); } // Called

Is it safe to use the same FluxSink from multiple threads concurrently

一个人想着一个人 提交于 2021-01-24 11:36:07
问题 I know a Publisher must not publish concurrently, but if I use Flux#create(FluxSink) , can I safely call FluxSink#next concurrently? In other words, does Spring have internal magic that ensures proper serial publishing of events even if FluxSink#next is called concurrently? public class FluxTest { private final Map<String, FluxSink<Item>> sinks = new ConcurrentHashMap<>(); // Store a new sink for the given ID public void start(String id) { Flux.create(sink -> sinks.put(id, sink)); } // Called

Spring Reactor: Mono.zip fails on empty Mono

淺唱寂寞╮ 提交于 2021-01-21 03:53:07
问题 I am using Spring Reactor 3.1.0.M3 and have a use case where I need to merge Mono's from multiple sources. I found that if one of the Monos is an empty Mono, zip fails without an error. Example: Mono<String> m1 = Mono.just("A"); Mono<String> m2 = Mono.just("B"); Mono<String> m3 = Mono.empty(); Mono<String> combined = Mono.zip(strings -> { StringBuffer sb = new StringBuffer(); for (Object string : strings) { sb.append((String) string); } return sb.toString(); }, m1, m2, m3); System.out.println

Spring Reactor: Mono.zip fails on empty Mono

a 夏天 提交于 2021-01-21 03:51:05
问题 I am using Spring Reactor 3.1.0.M3 and have a use case where I need to merge Mono's from multiple sources. I found that if one of the Monos is an empty Mono, zip fails without an error. Example: Mono<String> m1 = Mono.just("A"); Mono<String> m2 = Mono.just("B"); Mono<String> m3 = Mono.empty(); Mono<String> combined = Mono.zip(strings -> { StringBuffer sb = new StringBuffer(); for (Object string : strings) { sb.append((String) string); } return sb.toString(); }, m1, m2, m3); System.out.println

How to call Sinks.Many<T>.tryEmitNext from multiple threads?

匆匆过客 提交于 2021-01-05 11:25:14
问题 I am wrapping my head around Flux Sinks and cannot understand the higher-level picture. When using Sinks.Many<T> tryEmitNext , the function tells me if there was contention and what should I do in case of failure, (FailFast/Handler). But is there a simple construct which allows me to safely emit elements from multiple threads. For example, instead of letting the user know that there was contention and I should try again, maybe add elements to a queue(mpmc, mpsc etc), and only notify when the

The difference between onErrorResume and doOnError

百般思念 提交于 2020-12-29 12:13:37
问题 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:08:13
问题 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:08:12
问题 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