akka-stream

Alpakka MongoDB - specify type in MongoSource

天涯浪子 提交于 2019-12-10 11:48:34
问题 I'm currently playing around with Akka Streams and the Alpakka MongoDB connector. Is it possible to specify the type for MongoSource ? val codecRegistry = fromRegistries(fromProviders(classOf[TodoMongo]), DEFAULT_CODEC_REGISTRY) private val todoCollection: MongoCollection[TodoMongo] = mongoDb .withCodecRegistry(codecRegistry) .getCollection("todo") I would like to do something like this: val t: FindObservable[Seq[TodoMongo]] = todoCollection.find() MongoSource(t) // Stuck here But I get the

Akka Streams / HTTP: Get original request from response

家住魔仙堡 提交于 2019-12-10 11:16:08
问题 I have an Akka Streams source that goes through a flow and posts an HTTP request: source.map(toRequest) .via(Http().outgoingConnection(host)) .map(toMessage) Suppose that the toRequest method maps a string to an HttpRequest , and the toMessage method maps the HttpResponse to a message class that is needed to process downstream. Suppose that the message class needs to contain some of the original information. Is it possible to get the original HttpRequest from the HttpResponse ? If not, is

Closing an Akka stream from inside a GraphStage (Akka 2.4.2)

佐手、 提交于 2019-12-10 10:09:09
问题 In Akka Stream 2.4.2, PushStage has been deprecated. For Streams 2.0.3 I was using the solution from this answer: How does one close an Akka stream? which was: import akka.stream.stage._ val closeStage = new PushStage[Tpe, Tpe] { override def onPush(elem: Tpe, ctx: Context[Tpe]) = elem match { case elem if shouldCloseStream ⇒ // println("stream closed") ctx.finish() case elem ⇒ ctx.push(elem) } } How would I close a stream in 2.4.2 immediately, from inside a GraphStage / onPush() ? 回答1: Use

Create backpressure from a Future inside an Akka stream

萝らか妹 提交于 2019-12-10 03:39:38
问题 I'm new to Akka streams and streams in general so I might have completely misunderstood something at a conceptual level, but is there any way I can create backpressure until a future resolves? Essentially what I want to do is like this: object Parser { def parseBytesToSeq(buffer: ByteBuffer): Seq[ExampleObject] = ??? } val futures = FileIO.fromPath(path) .map(st => Parser.parseBytesToSeq(st.toByteBuffer)) .batch(1000, x => x)(_ ++ _) .map(values => doAsyncOp(values)) .runWith(Sink.seq) def

How to process future stream to create an instance of class with list property

爷,独闯天下 提交于 2019-12-09 02:19:29
I have a method that is takes in a future as parameter and also has a future inside it. I want to create a list from this method such that it takes values from the future that is passed in. Case Classes case class Color (colorName: String) case class Shade (shadeName: String) case class ColoShade (color: Color, shades: List[Shade]) Methods val shadesFuture: Future[Seq[Shade]] = { val larSource: Future[Seq[LoanApplicationRegister]] = getMySource(ctx, id) .map(_.utf8String) .map(_.trim) .map(s => ShadeParser(s)) .collect { case Right(shade) => shade } .runWith(Sink.seq) } //call the method

Waiting for a client websocket flow to connect before connecting source and sink

痴心易碎 提交于 2019-12-08 06:35:43
问题 I'm using akka-streams to set up a client web socket. I'm trying to encapsulate the setup in a method with the following signature: def createConnectedWebSocket(url: String): Flow[Message, Message, _] It is clear how to create the web socket flow but it is not connected yet: val webSocketFlow: Flow[Message, Message, Future[WebSocketUpgradeResponse]] = Http().webSocketClientFlow(WebSocketRequest(url)) I first want to Await the upgrade response future and then return the socket flow. However,

How to pass results from one source stream to another

蓝咒 提交于 2019-12-08 05:08:22
问题 I have a method that processes a Source and returns. I am trying to modify it but can't seem to be able to return the same thing: Original def originalMethod[as: AS, mat: MAT, ec: EC](checkType: String) : Flow[ByteString, MyValidation[MyClass], NotUsed]{ collectStuff .map { ts => val errors = MyEngine.checkAll(ts.code) (ts, errors) } .map { x => x._2 .leftMap(xs => { addInformation(x._1, xs.toList) }) .toEither } } I am modifying by using another source and pass result of that to the original

How to process future stream to create an instance of class with list property

怎甘沉沦 提交于 2019-12-08 03:59:48
问题 I have a method that is takes in a future as parameter and also has a future inside it. I want to create a list from this method such that it takes values from the future that is passed in. Case Classes case class Color (colorName: String) case class Shade (shadeName: String) case class ColoShade (color: Color, shades: List[Shade]) Methods val shadesFuture: Future[Seq[Shade]] = { val larSource: Future[Seq[LoanApplicationRegister]] = getMySource(ctx, id) .map(_.utf8String) .map(_.trim) .map(s

How to send a file as a response using akka http?

感情迁移 提交于 2019-12-08 03:08:19
问题 I am a little new to akka world, so my domain of knowledge is a bit small. I am creating an https server and handling it using akka streams and http, for a specific url, i need to send a file back to client. How can i achieve that using akka streams and avoiding the akka routes. def handleCall(request:HttpRequest):HttpResponse = { logger.info("Request is {}",request) val uri:String = request.getUri().path() if(uri == "/download"){ val f = new File("/1000.txt") logger.info("file download")

How to do akka-http request-level backpressure?

徘徊边缘 提交于 2019-12-07 19:59:04
问题 In akka-http, you can: Set akka.http.server.max-connections, which will prevent more than that number of connections. Exceeding this limit means clients will get connection timeouts. Set akka.http.server.pipelining-limit, which prevents a given connection from having more than this number of requests outstanding at once. Exceeding this means clients will get socket timeouts. These are both forms of backpressure from the http server to the client, but both are very low level, and only