reactive-streams

How are reactive streams used in Slick for inserting data

前提是你 提交于 2019-12-18 04:10:44
问题 In Slick's documentation examples for using Reactive Streams are presented just for reading data as a means of a DatabasePublisher. But what happens when you want to use your database as a Sink and backpreasure based on your insertion rate? I've looked for equivalent DatabaseSubscriber but it doesn't exist. So the question is, if I have a Source, say: val source = Source(0 to 100) how can I crete a Sink with Slick that writes those values into a table with schema: create table NumberTable

Stream records from DataBase using Akka Stream

≯℡__Kan透↙ 提交于 2019-12-17 19:36:50
问题 I have a system using Akka which currently handles incoming streaming data over message queues. When a record arrives then it is processed, mq is acked and record is passed on for further handling within the system. Now I would like to add support for using DBs as input. What would be a way to go for the input source to be able to handle DB (should stream in > 100M records at the pace that the receiver can handle - so I presume reactive/akka-streams?)? 回答1: Slick Library Slick streaming is

Akka Streams: What does Mat represents in Source[out, Mat]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 16:27:40
问题 In Akka streams what does Mat in Source[Out, Mat] or Sink[In, Mat] represent. When will it actually be used? 回答1: The Mat type parameter represents the type of the materialized value of this stream. Remember that in Akka Source , Flow , Sink (well, all graphs) are just blueprints - they do not do any processing by themselves, they only describe how the stream should be constructed. The process of turning these blueprints into a working stream with live data is called materialization . The

When FlatMap will listen to multiple sources concurrently?

限于喜欢 提交于 2019-12-11 16:42:48
问题 What are the situations which cause Flux::flatMap to listen to multiple sources (0...infinity) concurrently? I found out, while experimenting, that when the upstream send signals to flatMap in thread thread-upstream-1 and there are N inner streams which flatMap will listen to and each of them send signals in different thread: thread-inner-stream-i for 1<=i<=N , than for every 1<=i<=N if thread-upstream-1 != thread-inner-stream-i , flatMap will listen concurrently to all the inner streams. I

Splitting a WebClient Post of a Streaming Flux into JSON Arrays

馋奶兔 提交于 2019-12-11 06:49:08
问题 I am using a third-party REST controller which accepts an array of JSON objects and returns a single object response. When I POST from a WebClient using a limited Flux the code works (I assume, because the Flux completes). However, when the Flux is potentially unlimited, how do I; POST in chunks of arrays? Capture the response, per POSTed array? Stop the transmission of the Flux ? Here is my bean; public class Car implements Serializable { Long id; public Car() {} public Car(Long id) { this

In spring boot webflux based microservice, who is the subscriber?

点点圈 提交于 2019-12-11 01:41:05
问题 Note: Here the terms Subscriber and Subscription are being used from the reactive streams specification. Consider the following @RestController methods in a spring boot webflux based microservice. @GetMapping(path = "/users", produces = MediaType.APPLICATION_JSON_VALUE) public Flux<TradingUser> listUsers() { return this.tradingUserRepository.findAll(); } @GetMapping(path = "/users/{username}", produces = MediaType.APPLICATION_JSON_VALUE) public Mono<TradingUser> showUsers(@PathVariable String

Spring Boot Webflux/Netty - Detect closed connection

可紊 提交于 2019-12-09 11:52:42
问题 I've been working with spring-boot 2.0.0.RC1 using the webflux starter ( spring-boot-starter-webflux ). I created a simple controller that returns a infinite flux. I would like that the Publisher only does its work if there is a client (Subscriber). Let's say I have a controller like this one: @RestController public class Demo { @GetMapping(value = "/") public Flux<String> getEvents(){ return Flux.create((FluxSink<String> sink) -> { while(!sink.isCancelled()){ // TODO e.g. fetch data from

Can a Subscriber act as a Publisher?

蓝咒 提交于 2019-12-08 09:12:23
In terms of Reactive Streams, there is a Publisher and it could have as many Subscribers. But suppose, a subscriber gets a message from Publisher. Now this Subscriber(say Subs1) changes/modifies the message and passes it to some other Subscriber(say Subs2), which consumes the modified message. So can this Subs1 subscriber can act as a Publisher which can pass on message to new Subs2 subscriber? I am not sure if it possible or not, but the scenario is possible i think. If its possible, please suggest a possible way to do this. If we want to transform incoming message and pass it further to the

Can a Subscriber act as a Publisher?

核能气质少年 提交于 2019-12-08 08:47:19
问题 In terms of Reactive Streams, there is a Publisher and it could have as many Subscribers. But suppose, a subscriber gets a message from Publisher. Now this Subscriber(say Subs1) changes/modifies the message and passes it to some other Subscriber(say Subs2), which consumes the modified message. So can this Subs1 subscriber can act as a Publisher which can pass on message to new Subs2 subscriber? I am not sure if it possible or not, but the scenario is possible i think. If its possible, please

Reactor Flux<MyObject> to Mono<List<MyObject>>

时光总嘲笑我的痴心妄想 提交于 2019-12-08 02:17:07
问题 How can I convert Flux<MyObject> directly to Mono<List<MyObject>> ? I am looking for equivalent of Single<List<MyObject>> single = observable.toList() from RxJava. With blocking operator I can do it like this: val just: Mono<List<MyObject>> = Mono.just(flux.toIterable().toList()) But it is executed at the time of declaration which doesn't seam to be right. 回答1: Flux has the method collectList() doing just the same like toList() in Rx. val just: Mono<List<MyObject>> = flux.collectList() 来源: