akka-stream

How to add elements to Source dynamically?

可紊 提交于 2019-11-28 20:24:28
I have example code to generate an unbound source and working with it: object Main { def main(args : Array[String]): Unit = { implicit val system = ActorSystem("Sys") import system.dispatcher implicit val materializer = ActorFlowMaterializer() val source: Source[String] = Source(() => { Iterator.continually({ "message:" + ThreadLocalRandom.current().nextInt(10000)}) }) source.runForeach((item:String) => { println(item) }) .onComplete{ _ => system.shutdown() } } } I want to create class which implements: trait MySources { def addToSource(item: String) def getSource() : Source[String] } And I

How to use an Akka Streams SourceQueue with PlayFramework

二次信任 提交于 2019-11-28 19:06:38
问题 I would like to use a SourceQueue to push elements dynamically into an Akka Stream source. Play controller needs a Source to be able to stream a result using the chuncked method. As Play uses its own Akka Stream Sink under the hood, I can't materialize the source queue myself using a Sink because the source would be consumed before it's used by the chunked method (except if I use the following hack). I'm able to make it work if I pre-materialize the source queue using a reactive-streams

Why Akka streams cycle doesn't end in this graph?

有些话、适合烂在心里 提交于 2019-11-28 14:17:32
I would like to create a graph that loop n times before going to sink. I've just created this sample that fulfill my requirements but doesn't end after going to sink and I really don't understand why. Can someone enlighten me? Thanks. import akka.actor.ActorSystem import akka.stream.scaladsl._ import akka.stream.{ActorMaterializer, UniformFanOutShape} import scala.concurrent.Future object test { def main(args: Array[String]) { val ignore: Sink[Any, Future[Unit]] = Sink.ignore val closed: RunnableGraph[Future[Unit]] = FlowGraph.closed(ignore) { implicit b => sink => { import FlowGraph.Implicits

How to properly call Akka HTTP client for multiple (10k - 100k) requests?

一笑奈何 提交于 2019-11-28 05:32:16
I'm trying to write a tool for batch data upload using Akka HTTP 2.0-M2. But I'm facing akka.stream.OverflowStrategy$Fail$BufferOverflowException: Exceeded configured max-open-requests value of [32] error. I tried to isolate a problem and here is the sample code which also fails: public class TestMaxRequests { private static final class Router extends HttpApp { @Override public Route createRoute() { return route( path("test").route( get(handleWith(ctx -> ctx.complete("OK"))) ) ); } } public static void main(String[] args) { ActorSystem actorSystem = ActorSystem.create(); Materializer

Creating a flow from actor in Akka Streams

◇◆丶佛笑我妖孽 提交于 2019-11-28 03:24:19
It's possible to create sources and sinks from actors using Source.actorPublisher() and Sink.actorSubscriber() methods respectively. But is it possible to create a Flow from actor? Conceptually there doesn't seem to be a good reason not to, given that it implements both ActorPublisher and ActorSubscriber traits, but unfortunately, the Flow object doesn't have any method for doing this. In this excellent blog post it's done in an earlier version of Akka Streams, so the question is if it's possible also in the latest (2.4.9) version. I'm part of the Akka team and would like to use this question

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

爱⌒轻易说出口 提交于 2019-11-27 23:36:43
In Akka streams what does Mat in Source[Out, Mat] or Sink[In, Mat] represent. When will it actually be used? 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 core method for materializing a stream is called run() , and it is defined in the RunnableGraph class. All

Akka-Stream implementation slower than single threaded implementation

只谈情不闲聊 提交于 2019-11-27 14:28:05
UPDATE FROM 2015-10-30 based on Roland Kuhn Awnser: Akka Streams is using asynchronous message passing between Actors to implement stream processing stages. Passing data across an asynchronous boundary has an overhead that you are seeing here: your computation seems to take only about 160ns (derived from the single-threaded measurement) while the streaming solution takes roughly 1µs per element, which is dominated by the message passing. Another misconception is that saying “stream” implies parallelism: in your code all computation runs sequentially in a single Actor (the map stage), so no

How to add elements to Source dynamically?

不问归期 提交于 2019-11-27 12:54:22
问题 I have example code to generate an unbound source and working with it: object Main { def main(args : Array[String]): Unit = { implicit val system = ActorSystem("Sys") import system.dispatcher implicit val materializer = ActorFlowMaterializer() val source: Source[String] = Source(() => { Iterator.continually({ "message:" + ThreadLocalRandom.current().nextInt(10000)}) }) source.runForeach((item:String) => { println(item) }) .onComplete{ _ => system.shutdown() } } } I want to create class which

How to properly call Akka HTTP client for multiple (10k - 100k) requests?

微笑、不失礼 提交于 2019-11-27 05:34:03
问题 I'm trying to write a tool for batch data upload using Akka HTTP 2.0-M2. But I'm facing akka.stream.OverflowStrategy$Fail$BufferOverflowException: Exceeded configured max-open-requests value of [32] error. I tried to isolate a problem and here is the sample code which also fails: public class TestMaxRequests { private static final class Router extends HttpApp { @Override public Route createRoute() { return route( path("test").route( get(handleWith(ctx -> ctx.complete("OK"))) ) ); } } public

Creating a flow from actor in Akka Streams

大城市里の小女人 提交于 2019-11-27 05:07:36
问题 It's possible to create sources and sinks from actors using Source.actorPublisher() and Sink.actorSubscriber() methods respectively. But is it possible to create a Flow from actor? Conceptually there doesn't seem to be a good reason not to, given that it implements both ActorPublisher and ActorSubscriber traits, but unfortunately, the Flow object doesn't have any method for doing this. In this excellent blog post it's done in an earlier version of Akka Streams, so the question is if it's