akka-stream

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

时光总嘲笑我的痴心妄想 提交于 2019-12-05 21:31:32
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 defined buffers but I don´t understand how I can access all 100 elements from flow1 in flow2 and do some

Monitoring a closed graph Akka Stream

女生的网名这么多〃 提交于 2019-12-05 20:31:28
问题 If I have created a RunningGraph in Akka Stream, how can I know (from the outside) when all nodes are cancelled due to completion? when all nodes have been stopped due to an error? 回答1: I don't think there is a way to do it for an arbitrary graph, but if you have your graph under control, you just need to attach monitoring sinks to the output of each node which can fail or complete (these are nodes which have at least one output), for example: import akka.actor.Status // obtain graph parts

How do I supply an implicit value for an akka.stream.Materializer when sending a FakeRequest?

依然范特西╮ 提交于 2019-12-05 17:42:46
问题 I'm trying to make sense of the error(s) I'm seeing below, and to learn how to fix it. could not find implicit value for parameter materializer: akka.Stream.Materializer val fut: Future[Result] = action.apply(fakeRequest).run ^ not enough arguments for method run (implicit materializer: akka.stream.Materializer)scala.concurrent.Future[play.api.mvc.Result]. Unspecified value parameter materializer. val fut: Future[Result] = action.apply(fakeRequest).run ^ Here is the test code that produced

How to abruptly stop an akka stream Runnable Graph?

江枫思渺然 提交于 2019-12-05 12:57:41
I am not able to figure out how to stop akka stream Runnable Graph immediately ? How to use killswitch to achieve this? It has been just a few days that I started akka streams. In my case I am reading lines from a file and doing some operations in flow and writing to the sink. What I want to do is, stop reading file immediately whenever I want, and I hope this should possibly stop the whole running graph. Any ideas on this would be greatly appreciated. Thanks in advance. Since Akka Streams 2.4.3, there is an elegant way to stop the stream from the outside via KillSwitch . Consider the

Akka-http process HttpRequests from different connections in one flow

你说的曾经没有我的故事 提交于 2019-12-05 12:22:04
Akka-http documentation says: Apart from regarding a socket bound on the server-side as a Source[IncomingConnection] and each connection as a Source[HttpRequest] with a Sink[HttpResponse] Assume we get the merged source containing incoming connections from many Source[IncomingConnection]. Then, assume, we get Source[HttpRequest] from Source[IncomingConnection] (see the code below). Then, no problem, we can provide a flow to convert HttpRequest to HttpResponse. And here is the problem - how can we properly Sink the responses ? How can we join the responses to connections? The whole idea behind

akka stream consume web socket

百般思念 提交于 2019-12-05 09:10:54
Getting started with akka-streams I want to build a simple example. In chrome using a web socket plugin I simply can connect to a stream like this one https://blockchain.info/api/api_websocket via wss://ws.blockchain.info/inv and sending 2 commands {"op":"ping"} {"op":"unconfirmed_sub"} will stream the results in chromes web socket plugin window. I tried to implement the same functionality in akka streams but am facing some problems: 2 commands are executed, but I actually do not get the streaming output the same command is executed twice (the ping command) When following the tutorial of http:

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

人盡茶涼 提交于 2019-12-05 08:48:38
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(httpResponseToSprayJson[SearchResponse]).map { v => v.idlist.foreach { id => queue.offer(id) } queue.complete() } }

Can the subflows of groupBy depend on the keys they were generated from ?

老子叫甜甜 提交于 2019-12-05 07:54:00
I have a flow with data associated to users. I also have a state for each user, that I can get asynchronously from DB. I want to separate my flow with one subflow per user, and load the state for each user when materializing the subflow, so that the elements of the subflow can be treated with respect to this state. If I don't want to merge the subflows downstream, I can do something with groupBy and Sink.lazyInit : def getState(userId: UserId): Future[UserState] = ... def getUserId(element: Element): UserId = ... def treatUser(state: UserState): Sink[Element, _] = ... val treatByUser: Sink

Streaming file from server to client using Akka

試著忘記壹切 提交于 2019-12-05 01:30:20
问题 Basically I want to allow a user to download a csv file from the server. Assume the CSV file already exists on the server. A API endpoint is exposed via GET /export. How do I stream the file from Akka HTTP server to client? This is what I have so far... Service: def export(): Future[IOResult] = { FileIO.fromPath(Paths.get("file.csv")) .to(Sink.ignore) .run() } Route: pathPrefix("export") { pathEndOrSingleSlash { get { complete(HttpEntity(ContentTypes.`text/csv`, export()) } } } 回答1: The Akka

Akka Stream - Timer or Scheduler like CRON

ⅰ亾dé卋堺 提交于 2019-12-05 01:18:24
问题 I use Akka Stream on Scala. I'd like to set a scheduler which runs on every 24:00 . I tried to search for it. But I could't find what I want to do. Could you tell me how to write code? 回答1: Use the build in Akka scheduler, see: http://doc.akka.io/docs/akka/current/scala/scheduler.html You can use the scheduler like: system.scheduler.schedule( initialDelay = FiniteDuration(/*offset to next 24:00*/), interval = FiniteDuration(24, TimeUnit.HOURS), receiver = self, message = ScheduleAkkaStream )