Reactor

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

Reactor系列(十二)window嵌套

匆匆过客 提交于 2019-12-24 14:05:02
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> #java#reactor#flux#window# Flux嵌套 视频解说: https://www.bilibili.com/video/av80458406/ FluxMonoTestCase.java package com.example.reactor; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; @Slf4j public class FluxMonoTestCase extends BaseTestCase { @Test public void window(){ //一维Flux Flux<String> stringFlux1 = Flux.just("a","b","c","d","e","f","g","h","i"); //二维Flux Flux<Flux<String>> stringFlux2 = stringFlux1.window(2); stringFlux2.count().subscribe(System.out::println); //三维Flux Flux<Flux<Flux<String>>>

How to build a reactive pipeline with different Publishers without losing data?

浪尽此生 提交于 2019-12-24 06:46:27
问题 Imagine you have code like this: public List<Group> addUserToGroups(String username, String label) { Mono<User> userMono = webClient.getUser(username); User user = userMono.block(); Flux<Group> groupsFlux = webClient.getGroups(label); List<Group> groups = groupsFlux.collectList().block(); groups.forEach(group -> webClient.addUserToGroup(user.getId(), group.getId()).block() ); return groups; } But now you want to refactor this code into a non-blocking reactive pipeline, and the main method to

How to catch/detect exceptions in multi-threaded map/reduce using Reactor framework 2.x?

倾然丶 夕夏残阳落幕 提交于 2019-12-24 04:25:09
问题 I was playing with the code of this answer and it works smoothly. However, if an exception is thrown, the caller code does not catch it. How is an Exception captured in reactor 2.0 streams? What I want to do is: if an Exception is thrown, stream processing must stop. I need to throw the Exception up in the caller thread (the one that created the steam in first place). List<Map<String, Object>> data = readData(); Streams.from(data) .flatMap(m -> Streams.just(m) .dispatchOn(Environment

Should I use the async File IO methods over their synchronous equivalents for local files in node.js?

时间秒杀一切 提交于 2019-12-24 03:04:35
问题 I have a very simple utility script that I've written in JavaScript for node.js which reads a file, does a few calculations, then writes an output file. The source in its current form looks something like this: fs.readFile(inputPath, function (err, data) { if (err) throw err; // do something with the data fs.writeFile(outputPath, output, function (err) { if (err) throw err; console.log("File successfully written."); }); }); This works fine, but I'm wondering if there is any disadvantage in

Reactor系列(十一)take获取

谁都会走 提交于 2019-12-23 11:31:29
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> #java#reactor#flux#take#获取# 获取Flux订阅数量 视频讲解: https://www.bilibili.com/video/av80322616/ FluxMonoTestCase.java package com.example.reactor; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import java.time.Duration; @Slf4j public class FluxMonoTestCase extends BaseTestCase { @Test public void take(){ //根据数量获取 Flux.range(1,10).take(0).log().subscribe(System.out::println); //根据实际获取 Flux.range(1,10000).take(Duration.ofMillis(2)).log().subscribe(System.out::println); //根据条件获取 Flux.range(1,10).takeUntil(item

Kafka

…衆ロ難τιáo~ 提交于 2019-12-23 10:36:42
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Kafka 介绍 Kafka最早是由美国领英公司(LinkedIn)研发的,当时主要用于解决 数据管道 (data pipeline)的问题。当时在LinedIn内部有诸多子系统用于执行各种数据的收集与分析,主要包括业务系统和应用程序的性能监控指标数据和用户操作行为数据两大类。 由于使用开源框架来处理这些数据时存在的诸如扩展性不足,问题较多等一些难点,最终导致了Kafka出世。 Kafka设计之初就旨在提供3个方面的功能特性: 为生产者和消费者提供一套简单的API。 降低网络传输和磁盘存储开销。 具有高伸缩性架构。 在LinkedIn内部,Kafka既用于在线系统,也用于离线系统, 既从上游系统接收数据,也会给下游系统输送数据;既提供消息的流转服务,也用于数据的持久化存储。用Kafka来承接了大量的上下游子系统。 我们印象中的Kafka就是消息队列,也叫消息引擎。从以上可以知道Kafka用于充当系统与系统之间的消息传递的管道,中间件。这种消息引擎解耦了系统与系统之间的联系,给系统与系统之间提供了通过消息来通信,异步处理事件的能力。 系统图解: Kafka设计 吞吐量 对于任何一个消息引擎而言, 吞吐量 都是至关重要的性能指标。通常来讲 吞吐量是某种处理能力的最大值 对于Kafka而言

Is nodejs representing Reactor or Proactor design pattern?

[亡魂溺海] 提交于 2019-12-23 05:35:11
问题 Many articles online demonstrates nodejs as an example of reactor pattern. Isn't it rather proactor? As far as I understand, the difference between the two is: reactor handles events in a single thread (synchronously), proactor handles events is multiple threads (asynchronously) with completion callbacks. For example in this article: Reactor Pattern is an idea of non-blocking I/O operations in Node.js. This pattern provides a handler(in case of Node.js, a callback function) that is associated

WebFlux call `bodyToMono()` twice throws `IllegalStateException`

二次信任 提交于 2019-12-23 04:41:54
问题 I'm currently working on creating a logging ExchangeFilterFunction that can be used for any WebFlux WebClient to log both requests and responses. The issue I am running into is that when I attempt to log the body of the response I get the following: java.lang.IllegalStateException: Only one connection receive subscriber allowed. I understand why it's happening as Spring only allows one subscriber to the stream. My question is how can I obtain the body in two decoupled places? I have tried