akka-stream

Via/ViaMat/to/toMat in Akka Stream

假如想象 提交于 2020-01-22 05:03:13
问题 Can someone explain clearly what are the difference between those 4 methods ? When is it more appropriate to use each one ? Also generally speaking what is the name of this Group of method? Are there more method that does the same job ? A link to the scaladoc could also help. -D- 回答1: All these methods are necessary to join two streams into one stream. For example, you can create a Source out of a Source and a Flow , or you can create a Sink out of a Flow and a Sink , or you can create a Flow

Via/ViaMat/to/toMat in Akka Stream

徘徊边缘 提交于 2020-01-22 05:03:09
问题 Can someone explain clearly what are the difference between those 4 methods ? When is it more appropriate to use each one ? Also generally speaking what is the name of this Group of method? Are there more method that does the same job ? A link to the scaladoc could also help. -D- 回答1: All these methods are necessary to join two streams into one stream. For example, you can create a Source out of a Source and a Flow , or you can create a Sink out of a Flow and a Sink , or you can create a Flow

How to map a source onto another?

感情迁移 提交于 2020-01-16 13:18:06
问题 I have two case classes case class Color (name: String, shades: List[Shade] = List.empty) case class Shade (shadeName: String) I also have parsers for both: object ColorParser { def apply( s: String): Either[List[SomethingElse], Color] = { val values = s.split("\\|", -1).map(_.trim).toList validateColor(values).leftMap(xs => xs.toList).toEither } } object ShadesParser { def apply(s: String) : Either[List[SomethingElse], Shade] = { val values = s.split('|').map(_.trim).toList validateShade

How to integrate akka streams kafka (reactive-kafka) into akka http application?

只愿长相守 提交于 2020-01-14 06:42:11
问题 I have a basic scala akka http CRUD application. See below for the relevant classes. I'd simply like to write an entity id and some data (as json) to a Kafka topic whenever, for example, an entity is created/updated. I'm looking at http://doc.akka.io/docs/akka-stream-kafka/current/producer.html, but am new to scala and akka, and unsure of how to integrate it into my application? For example, from the docs above, this is the example of a producer writing to kafka, so I think I need to

How can I use and return Source queue to caller without materializing it?

前提是你 提交于 2020-01-13 10:53:14
问题 I'm trying to use new Akka streams and wonder how I can use and return Source queue to caller without materializing it in my code ? Imagine we have library that makes number of async calls and returns results via Source . Function looks like this def findArticlesByTitle(text: String): Source[String, SourceQueue[String]] = { val source = Source.queue[String](100, backpressure) source.mapMaterializedValue { case queue => val url = s"http://.....&term=$text" httpclient.get(url).map

How can I use and return Source queue to caller without materializing it?

ぃ、小莉子 提交于 2020-01-13 10:50:07
问题 I'm trying to use new Akka streams and wonder how I can use and return Source queue to caller without materializing it in my code ? Imagine we have library that makes number of async calls and returns results via Source . Function looks like this def findArticlesByTitle(text: String): Source[String, SourceQueue[String]] = { val source = Source.queue[String](100, backpressure) source.mapMaterializedValue { case queue => val url = s"http://.....&term=$text" httpclient.get(url).map

Akka.Net Streams - Source stops pulling elements when buffer throws error

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-06 05:15:30
问题 I've been playing a little with the streams extension package for Akka.Net and noticed this error at attempting to combine buffer and throttle methods: using (var system = ActorSystem.Create("test-system")) using (var materializer = system.Materializer(GetSettings(system))) { int index = 0; var sink = Sink.ActorRefWithAck<KeyValue>( system.ActorOf<Writer>(), new OnInitMessage(), new OnAcknowledgeMessage(), OnComplete.Instance, exception => new OnError(exception)); ServiceBusSource .Create

How to put contents of stream into a val?

眉间皱痕 提交于 2020-01-06 04:13:30
问题 I have a stream like this: def myStream[T: AS: MAT](source: Source[T, NotUsed]): Future[Seq[T]] = { return source.runWith(Sink.seq) } def myMethod(colorStream: Source[Color, NotUsed]) { val allColors = myStream(colorStream).map(_.toList) //how can I actually extract the things from allColors //so that I can call my method below? myOtherMethod if I do println(allColors.map(println _)) I can print the elements fine } def myOtherMethod(colors: Seq[Color] = List.empty()) { ... } 回答1: allColors is

Send data from InputStream over Akka/Spring stream

China☆狼群 提交于 2020-01-05 09:21:32
问题 Here is my previous question: Send big file over reactive stream I have managed to send file over Akka stream using FileIO.fromPath(Paths.get(file.toURI())) and it works fine. However, I would like to compress and encrypt file before sending it. I have created method, that opens FileInputStream, routes it through compression stream and then through encryption stream and now I would like to direct it into socket using Akka stream. File -> FileInputStream -> CompressedInputStream ->

Akka stream Source.queue hangs when using fail overflow strategy

时光总嘲笑我的痴心妄想 提交于 2020-01-05 08:18:24
问题 The following Scala snippet doesn't seem to return: val queue = Source.queue[Unit](10, OverflowStrategy.fail) .throttle(1, 1 second, 1, ThrottleMode.shaping) .to(Sink.ignore) .run() Await.result( (1 to 15).map(_ => queue.offer(())).last, Duration.Inf) Is this a bug in Akka streams or am I doing something wrong? EDIT: just to circle back, this bug was opened and accepted in Akka: https://github.com/akka/akka/issues/23078 回答1: This program gives more insight into what happens here: import akka