akka-http

How to handle response timeout?

ぐ巨炮叔叔 提交于 2019-12-21 04:53:29
问题 In akka-http routing I can return Future as a response that implicitly converts to ToResponseMarshaller . Is there some way to handle timeout of this future? Or timeout of connection in route level? Or one way is to use Await() function? Right now client can wait response forever. complete { val future = for { response <- someIOFunc() entity <- someOtherFunc() } yield entity future.onComplete({ case Success(result) => HttpResponse(entity = HttpEntity(MediaTypes.`text/xml`, result)) case

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

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

落花浮王杯 提交于 2019-12-20 05:24:09
问题 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

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

﹥>﹥吖頭↗ 提交于 2019-12-19 07:56:29
问题 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

Akka-http: Accept and Content-type handling

自闭症网瘾萝莉.ら 提交于 2019-12-18 03:58:21
问题 I'm trying out Akka-http and hopefully someone can shed light on a the following questions: How does one create different routes based on the accept: header in the request? For example, i want one code path to handle "json" and one to handle "xml" requests (with default to "json" if header is missing) In cases where I don't want the contentType to be inferred, how do i specify it? For example, in the code below I try to run the json through compactPrint() but this changes it to a string,

Conditionally skip flow using akka streams

纵饮孤独 提交于 2019-12-18 02:39:06
问题 I'm using akka streams and I have a segment of my graph that I need to conditionally skip because the flow can't handle certain values. Specifically, I have a flow that takes a string and makes http requests, but the server can't handle the case when the string is empty. But I need to just return an empty string instead. Is there a way of doing this without having to go through the http request knowing it will fail? I basically have this: val source = Source("1", "2", "", "3", "4") val

akka http (un)marshall traits

元气小坏坏 提交于 2019-12-13 17:55:13
问题 Let's assume the following Code: sealed trait Action { def run(): Boolean } case class SimpleAction(parameter: String) extends Actions { // some impl } case class ExtendedAction(parameter1: String, parameter2: String) extends Actions { // some impl } Now I want to define a webservice where one can retrieve the Actions. How can I Marshall the Action as it's just the trait and no specific Type? I have found this https://github.com/spray/spray-json#providing-jsonformats-for-other-types in the

How is Akka HTTP marshaling implemented under the hood?

こ雲淡風輕ζ 提交于 2019-12-13 16:23:26
问题 The following Scala code compiles: import spray.json.DefaultJsonProtocol._ import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ import akka.http.scaladsl.server.Directives.complete case class Item(name: String, id: Long) implicit val itemFormat = jsonFormat2(Item) val item = Item("xbox", 123) complete(item) with the following output in the worksheet: import spray.json.DefaultJsonProtocol._ import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ import akka.http