reactive-streams

How to convert Reactor Flux<String> to InputStream

梦想与她 提交于 2019-12-07 07:38:11
问题 Given that I have a Flux<String> of unknown size, how can I convert it into InputStream that other library is expecting? For example with WebClient I can achieve that using this approach WebClient.get('example.com').exchange.flatMap { it.bodyToMono(InputStreamResource::class.java) }.map { it.inputStream } but I can't figure out how to do the same when I have Flux<String> as an input? 回答1: There are probably many ways to do this. One possibility is to use PipedInputStream and PipedOutputStream

akka stream consume web socket

笑着哭i 提交于 2019-12-07 03:27:08
问题 Getting started with akka-streams I want to build a simple example. In chrome using a web socket plugin I simply can connect to a stream like this one https://blockchain.info/api/api_websocket via wss://ws.blockchain.info/inv and sending 2 commands {"op":"ping"} {"op":"unconfirmed_sub"} will stream the results in chromes web socket plugin window. I tried to implement the same functionality in akka streams but am facing some problems: 2 commands are executed, but I actually do not get the

Backpressure strategies for Akka Stream Source.queue not working

為{幸葍}努か 提交于 2019-12-06 11:12:38
问题 I'm trying to understand why the below code snippet is doing what it's doing. I would have thought that because the Sink cannot produce demand faster than the Source is producing content, then I would be getting dropped messages in response to some of the offers (overflow strategy is set to Drop Buffer) and also an error and queue closed message after the self destruct piece. The snippet: package playground import java.time.LocalDateTime import java.util.concurrent.atomic.AtomicInteger import

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

荒凉一梦 提交于 2019-12-06 05:25:51
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. Flux has the method collectList() doing just the same like toList() in Rx. val just: Mono<List<MyObject>> = flux.collectList() 来源: https://stackoverflow.com/questions/44039497/reactor-fluxmyobject-to-monolistmyobject

compose() vs. transform() vs. as() vs. map() in Flux and Mono

折月煮酒 提交于 2019-12-05 17:55:35
问题 Recently, I decided to try spring 5 with projectreactor.io (io.projectreactor:3.1.1). Does anyone know what the best case of using this functions? What cons and pros of using each of them and where they should be used? Good examples will be helpful. 回答1: You have two broadly different categories of operators here: Operators that work on the Flux itself transform and compose are for code mutualization When you compose chains of operators regularly and you have common operator usage patterns in

akka stream consume web socket

百般思念 提交于 2019-12-05 09:10:54
Getting started with akka-streams I want to build a simple example. In chrome using a web socket plugin I simply can connect to a stream like this one https://blockchain.info/api/api_websocket via wss://ws.blockchain.info/inv and sending 2 commands {"op":"ping"} {"op":"unconfirmed_sub"} will stream the results in chromes web socket plugin window. I tried to implement the same functionality in akka streams but am facing some problems: 2 commands are executed, but I actually do not get the streaming output the same command is executed twice (the ping command) When following the tutorial of http:

Backpressure strategies for Akka Stream Source.queue not working

烈酒焚心 提交于 2019-12-04 17:01:43
I'm trying to understand why the below code snippet is doing what it's doing. I would have thought that because the Sink cannot produce demand faster than the Source is producing content, then I would be getting dropped messages in response to some of the offers (overflow strategy is set to Drop Buffer) and also an error and queue closed message after the self destruct piece. The snippet: package playground import java.time.LocalDateTime import java.util.concurrent.atomic.AtomicInteger import akka.actor.{Actor, ActorLogging, ActorSystem, Props} import akka.stream.QueueOfferResult.{Dropped,

How do I subscribe to a reactive streams implementation running on a different JVM?

China☆狼群 提交于 2019-12-04 15:59:12
Let's assume we have two Akka Stream flows, each running on its own JVM. // A reactive streams publisher running on JVM 1: val stringPublisher: Publisher[String] = Source(() => "Lorem Ipsum".split("\\s").iterator).runWith(Sink.publisher[String]) // A reactive streams subscriber running on JVM 2: def subscriber: Subscriber[String] = Sink.foreach[String](println(_)).runWith(Source.subscriber[String]) // Subscribe the second stream to the first stream stringPublisher.subscribe(subscriber) This example runs fine on one JVM, but how can I subscribe to a publisher running on a different JVM? Do I

End-to-End Reactive Streaming RESTful service (a.k.a. Back-Pressure over HTTP)

廉价感情. 提交于 2019-12-04 13:35:59
问题 I have been trying to clarify this question online for a while without success, so I will try to ask it here. I would like to find some resource or example where it shows how I can build an end-to-end fully back-pressured REST service + client. What I mean is that I would like to see that, given a REST client that implements Reactive Streams (whether in Akka, JS, or whatever), I will have (and be able to "visualise") the back-pressure handled throughout a REST server built, e.g. with Akka

compose() vs. transform() vs. as() vs. map() in Flux and Mono

蓝咒 提交于 2019-12-04 03:20:24
Recently, I decided to try spring 5 with projectreactor.io (io.projectreactor:3.1.1). Does anyone know what the best case of using this functions? What cons and pros of using each of them and where they should be used? Good examples will be helpful. You have two broadly different categories of operators here: Operators that work on the Flux itself transform and compose are for code mutualization When you compose chains of operators regularly and you have common operator usage patterns in your application, you can mutualize this code or give it a more descriptive name by using compose and