spring-reactive

Spring Reactive Stream - Unexpected Shutdown

巧了我就是萌 提交于 2021-01-02 03:10:17
问题 We are using Spring Cloud Reactive Streams with RabbitMQ. Spring Reactive Stream appears to acknowledge the message as soon as it pulls it off the queue. So any errors unhandled exceptions that happens during the message processing need to be handled in the application (which is a different than a non-reactive stream where unhandled exceptions can be thrown and a message would be rejected, thus sending it to a dead letter queue). How are we supposed to deal with a sudden shutdown in an

Can you Flux.zip a mono and a flux and and repeat the mono value for every flux value?

风格不统一 提交于 2020-06-28 05:07:09
问题 Is it possible to do something like the code below? I have one service that makes an API call and another one which returns a stream of values. I need to modify every value by the value returned by the API call. return Flux.zip( someMono.get(), someFlux.Get(), (d, t) -> { //HERE D IS ALWAYS THE SAME AND T IS EVERY NEW FLUX VALUE }); I've tried with .repeat() for the Mono and it works, but it's calling the method every time there's a new Flux value and it's a API call, so it's not good. Is it

Spring WebClient: Retry with WebFlux.fn + reactor-addons

点点圈 提交于 2020-04-18 03:49:23
问题 I'm trying to add a conditional Retry for WebClient with Kotlin Coroutines + WebFlux.fn + reactor-addons: suspend fun ClientResponse.asResponse(): ServerResponse = status(statusCode()) .headers { headerConsumer -> headerConsumer.addAll(headers().asHttpHeaders()) } .body(bodyToMono(DataBuffer::class.java), DataBuffer::class.java) .retryWhen { Retry.onlyIf { ctx: RetryContext<Throwable> -> (ctx.exception() as? WebClientResponseException)?.statusCode in retryableErrorCodes } .exponentialBackoff

Spring WebClient: Retry with WebFlux.fn + reactor-addons

允我心安 提交于 2020-04-18 03:49:07
问题 I'm trying to add a conditional Retry for WebClient with Kotlin Coroutines + WebFlux.fn + reactor-addons: suspend fun ClientResponse.asResponse(): ServerResponse = status(statusCode()) .headers { headerConsumer -> headerConsumer.addAll(headers().asHttpHeaders()) } .body(bodyToMono(DataBuffer::class.java), DataBuffer::class.java) .retryWhen { Retry.onlyIf { ctx: RetryContext<Throwable> -> (ctx.exception() as? WebClientResponseException)?.statusCode in retryableErrorCodes } .exponentialBackoff

How to await when all Disposable elements will be finished?

此生再无相见时 提交于 2019-12-25 01:37:23
问题 Lets consider following code: List<Mono<String>> monoList= apiCall(); List<Disposable> disposableList = monoList.stream() .map(m-> m.subscribe(str-> { log.info("Mono is finished with "+ str); }) ).collect(Collectors.toList()); // I need to await here I need to await when all mono will be finished. How could I achieve it? 回答1: Not mixing different streaming APIs you could utilize side effects instead of subscriptions and await completion with then() Mono<Void> await = Flux .fromIterable

How to convert List<Mono<String>> into Flux<List<String>>?

断了今生、忘了曾经 提交于 2019-12-25 01:12:23
问题 List<Mono<String>> responses = apiCall() I would like to get Flux<String> to await all mono-s from list. How could I achieve it ? P.S. I've found similar question but I need vice versa operation https://stackoverflow.com/a/44040346/2674303 回答1: You could use Flux.mergeSequential() and Flux.collectList() Mono<List<String>> list = Flux.mergeSequential(apiCall()).collectList(); 来源: https://stackoverflow.com/questions/58913554/how-to-convert-listmonostring-into-fluxliststring

Mono/Flux published on ExecutorService does not terminate as expected

血红的双手。 提交于 2019-12-11 14:07:24
问题 I tested a little around with the proposal in this thread: flux within executorservice and i have simplified the example a little to understand it easier. So, heres the example: ExecutorService executorService = Executors.newSingleThreadExecutor(); Flux.just("1", "2", "3").subscribeOn(Schedulers.fromExecutorService(executorService)).doOnNext(System.out::println).subscribe(); try { executorService.awaitTermination(10, TimeUnit.SECONDS); } catch (InterruptedException e) { // TODO Auto-generated

Why webClient doesn't do any http call?

蹲街弑〆低调 提交于 2019-11-26 17:53:04
问题 I have following code: List<Mono<MyResponseDTO>> monoList = queue.stream() .map(jobStatusBunch -> webClient .post() .uri("localhost:8080/api/some/url") .bodyValue(convertToRequestDto(someBean)) .retrieve() .toEntity(String.class) .filter(HttpEntity::hasBody) .map(stringResponseEntity -> { try { return objectMapper.readValue(stringResponseEntity.getBody(), MyResponseDTO.class); } catch (JsonProcessingException e) { log.error("Can't parse", e); return null; } }) .doOnNext(myResponseDTO -> { log