akka-stream

Chain Akka-http-client requests in a Stream

心已入冬 提交于 2019-12-03 12:53:39
问题 I would like to chain http request using akka-http-client as Stream. Each http request in a chain depends on a success/response of a previous requests and uses it to construct a new request. If a request is not successful, the Stream should return the response of the unsuccessful request. How can I construct such a stream in akka-http? which akka-http client level API should I use? 回答1: If you're making a web crawler, have a look at this post. This answer tackles a more simple case, such as

Split Akka Stream Source into two

瘦欲@ 提交于 2019-12-03 10:53:34
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 method and left part to handleFailure method. I tried using Broadcast splitter but it requires Sink s at

Why is Akka Streams swallowing my exceptions?

别来无恙 提交于 2019-12-03 09:36:36
问题 Why is the exception in import akka.actor.ActorSystem import akka.stream.ActorMaterializer import akka.stream.scaladsl.Source object TestExceptionHandling { def main(args: Array[String]): Unit = { implicit val actorSystem = ActorSystem() implicit val materializer = ActorMaterializer()(defaultActorSystem) Source(List(1, 2, 3)).map { i => if (i == 2) { throw new RuntimeException("Please, don't swallow me!") } else { i } }.runForeach { i => println(s"Received $i") } } } silently ignored? I can

What is the right way to work with slick's 3.0.0 streaming results and Postgresql?

限于喜欢 提交于 2019-12-03 09:16:32
问题 I am trying to figure out how to work with slick streaming. I use slick 3.0.0 with postgres driver The situation is following: server have to give client sequences of data split into chunks limited by size(in bytes). So, I wrote following slick query: val sequences = TableQuery[Sequences] def find(userId: Long, timestamp: Long) = sequences.filter(s ⇒ s.userId === userId && s.timestamp > timestamp).sortBy(_.timestamp.asc).result val seq = db.stream(find(0L, 0L)) I combined seq with akka

How to use Akka-HTTP client websocket send message

有些话、适合烂在心里 提交于 2019-12-03 08:47:25
I'm trying client-side websocket by following doc at webSocketClientFlow . sample code is: import akka.actor.ActorSystem import akka.Done import akka.http.scaladsl.Http import akka.stream.ActorMaterializer import akka.stream.scaladsl._ import akka.http.scaladsl.model._ import akka.http.scaladsl.model.ws._ import scala.concurrent.Future object WebSocketClientFlow { def main(args: Array[String]) = { implicit val system = ActorSystem() implicit val materializer = ActorMaterializer() import system.dispatcher // Future[Done] is the materialized value of Sink.foreach, // emitted when the stream

End-to-End Reactive Streaming RESTful service (a.k.a. Back-Pressure over HTTP)

五迷三道 提交于 2019-12-03 08:36:34
I have been trying to clarify this question online for a while without success, so I will try to ask it here. I would like to find some resource or example where it shows how I can build an end-to-end fully back-pressured REST service + client. What I mean is that I would like to see that, given a REST client that implements Reactive Streams (whether in Akka, JS, or whatever), I will have (and be able to "visualise") the back-pressure handled throughout a REST server built, e.g. with Akka-Http. To be clear, I am searching for something like the following talk (but I could not find slides or

Reading a CSV files using Akka Streams

丶灬走出姿态 提交于 2019-12-03 06:03:18
I'm reading a csv file. I am using Akka Streams to do this so that I can create a graph of actions to perform on each line. I've got the following toy example up and running. def main(args: Array[String]): Unit = { implicit val system = ActorSystem("MyAkkaSystem") implicit val materializer = ActorMaterializer() val source = akka.stream.scaladsl.Source.fromIterator(Source.fromFile("a.csv").getLines) val sink = Sink.foreach(println) source.runWith(sink) } The two Source types don't sit easy with me. Is this idiomatic or is there is a better way to write this? fcat Actually, akka-streams provides

Chain Akka-http-client requests in a Stream

我只是一个虾纸丫 提交于 2019-12-03 03:08:39
I would like to chain http request using akka-http-client as Stream. Each http request in a chain depends on a success/response of a previous requests and uses it to construct a new request. If a request is not successful, the Stream should return the response of the unsuccessful request. How can I construct such a stream in akka-http? which akka-http client level API should I use? If you're making a web crawler, have a look at this post . This answer tackles a more simple case, such as downloading paginated resources, where the link to the next page is in a header of the current page response

Why is Akka Streams swallowing my exceptions?

给你一囗甜甜゛ 提交于 2019-12-03 00:15:11
Why is the exception in import akka.actor.ActorSystem import akka.stream.ActorMaterializer import akka.stream.scaladsl.Source object TestExceptionHandling { def main(args: Array[String]): Unit = { implicit val actorSystem = ActorSystem() implicit val materializer = ActorMaterializer()(defaultActorSystem) Source(List(1, 2, 3)).map { i => if (i == 2) { throw new RuntimeException("Please, don't swallow me!") } else { i } }.runForeach { i => println(s"Received $i") } } } silently ignored? I can see that the stream gets stopped after printing Received 1 , but nothing is logged. Note that the

Via/ViaMat/to/toMat in Akka Stream

怎甘沉沦 提交于 2019-12-02 18:16:17
Can someone explain clearly what are the difference between those 4 methods ? When is it more appropriate to use each one ? Also generally speaking what is the name of this Group of method? Are there more method that does the same job ? A link to the scaladoc could also help. -D- All these methods are necessary to join two streams into one stream. For example, you can create a Source out of a Source and a Flow , or you can create a Sink out of a Flow and a Sink , or you can create a Flow out of two Flow s. For this, there are two basic operations, to and via . The former allows one to connect