akka-stream

How to get started with Akka Streams? [closed]

ⅰ亾dé卋堺 提交于 2019-12-02 13:46:07
The Akka Streams library already comes with quite a wealth of documentation . However, the main problem for me is that it provides too much material - I feel quite overwhelmed by the number of concepts that I have to learn. Lots of examples shown there feel very heavyweight and can't easily be translated to real world use cases and are therefore quite esoteric. I think it gives way too much details without explaining how to build all the building blocks together and how exactly it helps to solve specific problems. There are sources, sinks, flows, graph stages, partial graphs, materialization,

How to make a POST call to self-certified server with akka-http

自闭症网瘾萝莉.ら 提交于 2019-12-02 06:01:59
I have a akka-streams topology, where I make a POST call using akka-http. I am getting following error when hitting the post request to a un-secure server(having self-signed certs). It is a internal server, so I am fine from security point of view. javax.net.ssl.SSLHandshakeException: General SSLEngine problem at sun.security.ssl.Handshaker.checkThrown(Handshaker.java:1478) ~[?:1.8.0_131] at sun.security.ssl.SSLEngineImpl.checkTaskThrown(SSLEngineImpl.java:535) ~[?:1.8.0_131] at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:813) ~[?:1.8.0_131] at sun.security.ssl

How to respond with the result of an actor call?

怎甘沉沦 提交于 2019-12-01 18:35:03
问题 We are looking at using Akka-HTTP Java API - using Routing DSL. It's not clear how to use the Routing functionality to respond to an HttpRequest; using an Untyped Akka Actor. For example, upon matching a Route path, how do we hand off the request to a "handler" ActorRef, which will then respond with a HttpResponse in a asynchronous way? A similar question was posted on Akka-User mailing list, but with no followup solutions as such - https://groups.google.com/d/msg/akka-user/qHe3Ko7EVvg/KC-aKz

Custom Supervision.Decider doesn't catch exception produced by ActorPublisher

随声附和 提交于 2019-12-01 17:27:39
I'm building a library that is going to be used by 3rd-party. In one of my methods I return Stream[Item] that is asynchronously generated from result of paginated REST API call. I'm using my modification of BulkPullerAsync . My code is here . I want recipient of my stream to be able to handle errors. According to documentation I'm supposed to use custom Supervision.Decider . val decider: Supervision.Decider = { case ex => ex.printStackTrace() Supervision.Stop } implicit val mat = ActorMaterializer(ActorMaterializerSettings(system).withSupervisionStrategy(decider)) Unfortunately it doesn't

Custom Supervision.Decider doesn't catch exception produced by ActorPublisher

ぃ、小莉子 提交于 2019-12-01 16:52:16
问题 I'm building a library that is going to be used by 3rd-party. In one of my methods I return Stream[Item] that is asynchronously generated from result of paginated REST API call. I'm using my modification of BulkPullerAsync. My code is here. I want recipient of my stream to be able to handle errors. According to documentation I'm supposed to use custom Supervision.Decider . val decider: Supervision.Decider = { case ex => ex.printStackTrace() Supervision.Stop } implicit val mat =

Idiomatic way to use Spark DStream as Source for an Akka stream

試著忘記壹切 提交于 2019-12-01 06:03:28
I'm building a REST API that starts some calculation in a Spark cluster and responds with a chunked stream of the results. Given the Spark stream with calculation results, I can use dstream.foreachRDD() to send the data out of Spark. I'm sending the chunked HTTP response with akka-http: val requestHandler: HttpRequest => HttpResponse = { case HttpRequest(HttpMethods.GET, Uri.Path("/data"), _, _, _) => HttpResponse(entity = HttpEntity.Chunked(ContentTypes.`text/plain`, source)) } For simplicity, I'm trying to get plain text working first, will add JSON marshalling later. But what is the

Proper way to stop Akka Streams on condition

痞子三分冷 提交于 2019-12-01 02:48:53
I have been successfully using FileIO to stream the contents of a file, compute some transformations for each line and aggregate/reduce the results. Now I have a pretty specific use case, where I would like to stop the stream when a condition is reached, so that it is not necessary to read the whole file but the process finishes as soon as possible. What is the recommended way to achieve this? If the stop condition is "on the outside of the stream" There is a advanced building-block called KillSwitch that you could use to do this: http://doc.akka.io/japi/akka/2.4.7/akka/stream/KillSwitches

Akka streams: Reading multiple files

别等时光非礼了梦想. 提交于 2019-11-30 21:11:14
I have a list of files. I want: To read from all of them as a single Source. Files should be read sequentially, in-order. (no round-robin) At no point should any file be required to be entirely in memory. An error reading from a file should collapse the stream. It felt like this should work: (Scala, akka-streams v2.4.7) val sources = Seq("file1", "file2").map(new File(_)).map(f => FileIO.fromPath(f.toPath) .via(Framing.delimiter(ByteString(System.lineSeparator), 10000, allowTruncation = true)) .map(bs => bs.utf8String) ) val source = sources.reduce( (a, b) => Source.combine(a, b)

Close akka-http websocket connection from server

匆匆过客 提交于 2019-11-30 20:15:37
In my scenario, a client sends "goodbye" websocket message and I need to close previously established connection at the server side. From akka-http docs : Closing connections is possible by cancelling the incoming connection Flow from your server logic (e.g. by connecting its downstream to a Sink.cancelled and its upstream to a Source.empty). It is also possible to shut down the server's socket by cancelling the IncomingConnection source connections. But it's not clear to me how to do that taking into account that Sink and Source are set once when negotiating a new connection: (get & path("ws"

Websocket Proxy using Play 2.6 and akka streams

筅森魡賤 提交于 2019-11-30 15:09:58
I'm trying to create a simple Proxy for Websocket connections using Play and akka streams. The traffic flow is like this: (Client) request -> -> request (Server) Proxy (Client) response <- <- response (Server) I came up with the following code after following some examples: def socket = WebSocket.accept[String, String] { request => val uuid = UUID.randomUUID().toString // wsOut - actor that deals with incoming websocket frame from the Client // wsIn - publisher of the frame for the Server val (wsOut: ActorRef, wsIn: Publisher[String]) = { val source: Source[String, ActorRef] = Source.actorRef