akka-stream

Akka stream Source.queue hangs when using fail overflow strategy

醉酒当歌 提交于 2020-01-05 08:18:02
问题 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

Handle Akka stream's first element specially

时光总嘲笑我的痴心妄想 提交于 2020-01-01 09:12:12
问题 Is there an idiomatic way of handling Akka stream's Source first element in a special way? What I have now is: var firstHandled = false source.map { elem => if(!firstHandled) { //handle specially firstHandled = true } else { //handle normally } } Thanks 回答1: While I would generally go with Ramon's answer, you could also use prefixAndTail, with a prefix of 1, together with flatMapConcat to achieve something similar: val src = Source(List(1, 2, 3, 4, 5)) val fst = Flow[Int].map(i => s"First: $i

Consume TCP stream and redirect it to another Sink (with Akka Streams)

北城余情 提交于 2020-01-01 05:29:12
问题 I try to redirect/forward a TCP stream to another Sink with Akka 2.4.3. The program should open a server socket, listen for incoming connections and then consume the tcp stream. Our sender does not expect/accept replies from us so we never send back anything - we just consume the stream. After framing the tcp stream we need to transform the bytes into something more useful and send it to the Sink. I tried the following so far but i struggle especially with the part how to not sending tcp

How to create akka-http client with backpressure overflow strategy?

青春壹個敷衍的年華 提交于 2019-12-24 18:42:43
问题 I have undefined amount of akka-http client flows downloading data from an http service. I'm using akka-http host-level connection pooling because I would like to customise the pool, since there are long running requests going through it. Since, the number of clients is undefined and dynamic, I don't know how to configure the connection pool (max-open-requests/max-connections). Additionally, I might want the connection pool to be small (less than number of clients) to not damage the bandwidth

Exceeded configured max-open-requests

一个人想着一个人 提交于 2019-12-24 13:38:31
问题 recently I started to build some small web processing service using akka streams. It's quite simple, I'm pulling urls from redis, then I'm downloading those urls(they are images) later I'm processing images, and pushing them to s3 and some json to redis. I'm downloading lot of different kinds of images from multiple sites, I'm getting whole bunch of errors like 404, Unexpected disconnect , Response Content-Length 17951202 exceeds the configured limit of 8388608, EntityStreamException: Entity

Default value for MergeLatest

此生再无相见时 提交于 2019-12-24 07:24:18
问题 The official documentation of MergeLatest states: MergeLatest emits list for each element emitted from some input stream, but only after each input stream emitted at least one element. My question is: can this be bypassed? For example, can we provide a default value such that it will start producing lists as soon as it receives at least one element from any input stream? The following should be the new behavior: (1,0,0) (2,0,0) (2,1,0) (2,1,1) (2,1,2) Instead of: (2,1,1) (2,1,2) As I need

Pushing messages via web sockets with akka http

雨燕双飞 提交于 2019-12-24 02:05:31
问题 I am using akka http 2.0.3 for an app and want to use web sockets. I want to be able to push messages from the server to the client, without having to receive a message first. So, I was looking at the UpgradeToWebsocket trait and it looked like using 'handleMessagesWithSinkSource' would be the right thing. Now, for pushing the messages I wanted to have an actor connected to a source which is passed to the 'handleMessagesWithSinkSource' method. However, when using the 'Source.actorRef' method

How to Enable Source.Queue Backpressure

坚强是说给别人听的谎言 提交于 2019-12-23 19:27:45
问题 I'm using host-level API with a queue. private val (queueSource, connectionPool) = Source.queue[(HttpRequest, Promise[HttpResponse])](queueSize, OverflowStrategy.backpressure).async .viaMat(poolFlow)(Keep.both) .toMat( Sink.foreach({ case ((Success(resp), p)) => p.success(resp) case ((Failure(e), p)) => p.failure(e) }) )(Keep.left) .run() I have a lot of request racing for connections in the connection pool but I get the following error: java.lang.IllegalStateException: You have to wait for

How do I group items of sorted stream with SubFlows?

烈酒焚心 提交于 2019-12-23 16:17:42
问题 Could you guys explain how to use new groupBy in akka-streams ? Documentation seems to be quite useless. groupBy used to return (T, Source) but not anymore. Here is my example (I mimicked one from docs): Source(List( 1 -> "1a", 1 -> "1b", 1 -> "1c", 2 -> "2a", 2 -> "2b", 3 -> "3a", 3 -> "3b", 3 -> "3c", 4 -> "4a", 5 -> "5a", 5 -> "5b", 5 -> "5c", 6 -> "6a", 6 -> "6b", 7 -> "7a", 8 -> "8a", 8 -> "8b", 9 -> "9a", 9 -> "9b", )) .groupBy(3, _._1) .map { case (aid, raw) => aid -> List(raw) }

akka-stream Zipping Flows with SubFlows

拥有回忆 提交于 2019-12-23 12:28:46
问题 I've a short question about akka-streams. Basically, I try to split a stream into two streams, one of these two streams will be split again in multiple subFlows using groupBy, each of these subFlows needs to be connected with the other stream (zip). I tried to illustrate this here: Here is what I got so far val aggFlow = Flow.fromGraph(GraphDSL.create() { implicit builder => val broadcast = builder.add(Broadcast[Event](2)) val zip = builder .add(ZipWith[ChangedEvent, Long, (ChangedEvent, Long