akka-stream

How can I modify my Akka streams Prime sieve to exclude modulo checks for known primes?

雨燕双飞 提交于 2019-12-23 01:41:32
问题 I wrote a sieve using akka streams to find prime members of an arbitrary source of Int : object Sieve extends App { implicit val system = ActorSystem() implicit val mat = ActorMaterializer(ActorMaterializerSettings(system)) implicit val ctx = implicitly[ExecutionContext](system.dispatcher) val NaturalNumbers = Source.fromIterator(() => Iterator.from(2)) val IsPrimeByEurithmethes: Flow[Int, Int, _] = Flow[Int].filter { case n: Int => (2 to Math.floor(Math.sqrt(n)).toInt).par.forall(n % _ != 0)

Akka-Streams collecting data (Source -> Flow -> Flow (collect) -> Sink)

放肆的年华 提交于 2019-12-22 09:55:30
问题 I'm totally new in Scala and Akka. I've a simple RunnableFlow: Source -> Flow (do some transformation) -> Sink.runForeach Now I want something like this: Source -> Flow1 (do some transformation) -> Flow2 (do some transformation) -> Sink.runForeach But Flow2 should wait until 100 elements from Flow1 are available and then transform these 100 elements to a new element (which needs all 100 elements from Flow1) and give this new element to the Sink. I did some research and found Explicit user

Is connection pooling in akka-http using the source queue Implementation thread safe?

一个人想着一个人 提交于 2019-12-22 05:13:08
问题 Refering to the following implementation mentioned in: http://doc.akka.io/docs/akka-http/10.0.5/scala/http/client-side/host-level.html val poolClientFlow = Http().cachedHostConnectionPool[Promise[HttpResponse]]("akka.io") val queue = Source.queue[(HttpRequest, Promise[HttpResponse])](QueueSize, OverflowStrategy.dropNew) .via(poolClientFlow) .toMat(Sink.foreach({ case ((Success(resp), p)) => p.success(resp) case ((Failure(e), p)) => p.failure(e) }))(Keep.left) .run() Is it thread safe to offer

How can Akka streams be materialized continually?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 14:36:11
问题 I am using Akka Streams in Scala to poll from an AWS SQS queue using the AWS Java SDK. I created an ActorPublisher which dequeues messages on a two second interval: class SQSSubscriber(name: String) extends ActorPublisher[Message] { implicit val materializer = ActorMaterializer() val schedule = context.system.scheduler.schedule(0 seconds, 2 seconds, self, "dequeue") val client = new AmazonSQSClient() client.setRegion(RegionUtils.getRegion("us-east-1")) val url = client.getQueueUrl(name)

Akka Stream + Akka Http - Get Request on Error

强颜欢笑 提交于 2019-12-21 06:06:27
问题 I have the following stream that works pretty well: source .map(x => HttpRequest(uri = x.rawRequest)) .via(Http().outgoingConnection(host, port)) .to(Sink.actorRef(myActor, IsDone)) .run() and a simple actor to handle the response status and the final message when the stream completes: /** * A simple actor to count how many rows have been processed * in the complete process given a http status * * It also finish the main thread upon a message of type [[IsDone]] is received */ class MyActor

How to log flow rate in Akka Stream?

北城以北 提交于 2019-12-21 06:05:09
问题 I have an Akka Stream application with a single flow/graph. I want to measure the flow rate at the source and log it every 5 seconds, like 'received 3 messages in the last 5 seconds'. I tried with, someOtherFlow .groupedWithin(Integer.MAX_VALUE, 5 seconds) .runForeach(seq => log.debug(s"received ${seq.length} messages in the last 5 seconds") ) but it only outputs when there are messages, no empty list when there are 0 messages. I want the 0's as well. Is this possible? 回答1: You could try

How to send a message in a reactive stream from a subscriber to a publisher in a web socket connection

放肆的年华 提交于 2019-12-21 04:53:14
问题 My application has an Akka-Websocket interface. The web socket consists of an actor-subscriber and an actor publisher. The subscriber handles commands, by sending them to the corresponding actor. The publisher listens on the event stream and publishes update informations back to the stream (and so finally to the client). This works well. My question: How is it possible for the Subscriber to send an event back to the stream? For example to confirm the execution of a received command. public

Akka Flow hangs when making http requests via connection pool

随声附和 提交于 2019-12-21 04:31:12
问题 I'm using Akka 2.4.4 and trying to move from Apache HttpAsyncClient (unsuccessfully). Below is simplified version of code that I use in my project. The problem is that it hangs if I send more than 1-3 requests to the flow. So far after 6 hours of debugging I couldn't even locate the problem. I don't see exceptions, error logs, events in Decider . NOTHING :) I tried reducing connection-timeout setting to 1s thinking that maybe it's waiting for response from the server but it didn't help. What

Akka Flow hangs when making http requests via connection pool

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-21 04:31:09
问题 I'm using Akka 2.4.4 and trying to move from Apache HttpAsyncClient (unsuccessfully). Below is simplified version of code that I use in my project. The problem is that it hangs if I send more than 1-3 requests to the flow. So far after 6 hours of debugging I couldn't even locate the problem. I don't see exceptions, error logs, events in Decider . NOTHING :) I tried reducing connection-timeout setting to 1s thinking that maybe it's waiting for response from the server but it didn't help. What

Split Akka Stream Source into two

陌路散爱 提交于 2019-12-21 03:36:32
问题 I have an Akka Streams Source which I want to split into two sources according to a predicate. E.g. having a source (types are simplified intentionally): val source: Source[Either[Throwable, String], NotUsed] = ??? And two methods: def handleSuccess(source: Source[String, NotUsed]): Future[Unit] = ??? def handleFailure(source: Source[Throwable, NotUsed]): Future[Unit] = ??? I would like to be able to split the source according to _.isRight predicate and pass the right part to handleSuccess