akka-http

Should I use akka.http.scaladsl.util.FastFuture instead of scala.concurrent.Future?

房东的猫 提交于 2019-12-24 02:25:12
问题 Should I use akka.http.scaladsl.util.FastFuture instead of scala.concurrent.Future? The comment says : /** * Provides alternative implementations of the basic transformation operations defined on [[scala.concurrent.Future]], * which try to avoid scheduling to an [[scala.concurrent.ExecutionContext]] if possible, i.e. if the given future * value is already present. */ Do I get any performance improvement especially when I need to use Future.apply , Future.successful or Future.failed ? What

Pushing messages via web sockets with akka http

雨燕双飞 提交于 2019-12-24 02:05:31
问题 I am using akka http 2.0.3 for an app and want to use web sockets. I want to be able to push messages from the server to the client, without having to receive a message first. So, I was looking at the UpgradeToWebsocket trait and it looked like using 'handleMessagesWithSinkSource' would be the right thing. Now, for pushing the messages I wanted to have an actor connected to a source which is passed to the 'handleMessagesWithSinkSource' method. However, when using the 'Source.actorRef' method

How to Enable Source.Queue Backpressure

坚强是说给别人听的谎言 提交于 2019-12-23 19:27:45
问题 I'm using host-level API with a queue. private val (queueSource, connectionPool) = Source.queue[(HttpRequest, Promise[HttpResponse])](queueSize, OverflowStrategy.backpressure).async .viaMat(poolFlow)(Keep.both) .toMat( Sink.foreach({ case ((Success(resp), p)) => p.success(resp) case ((Failure(e), p)) => p.failure(e) }) )(Keep.left) .run() I have a lot of request racing for connections in the connection pool but I get the following error: java.lang.IllegalStateException: You have to wait for

Akka HTTP Connection Pool Hangs After Couple of Hours

妖精的绣舞 提交于 2019-12-22 10:07:28
问题 I have an HTTP Connection Pool that hangs after a couple of hours of running: private def createHttpPool(host: String): SourceQueue[(HttpRequest, Promise[HttpResponse])] = { val pool = Http().cachedHostConnectionPoolHttps[Promise[HttpResponse]](host) Source.queue[(HttpRequest, Promise[HttpResponse])](config.poolBuffer, OverflowStrategy.dropNew) .via(pool).toMat(Sink.foreach { case ((Success(res), p)) => p.success(res) case ((Failure(e), p)) => p.failure(e) })(Keep.left).run } I enqueue items

Akka Http Client :Custom headers

假装没事ソ 提交于 2019-12-22 05:20:35
问题 I am trying to use Akka-Http for invoking REST url. I am following this example from the akka documentation. Using this I am able to make the rest call. But I am not able to find out how to add custom request headers. I tried using ModeledCustomHeader, but still request is not having header. Here is my example. final class ApiTokenHeader(token: String) extends ModeledCustomHeader[ApiTokenHeader] { override def renderInRequests = false override def renderInResponses = false override val

Is connection pooling in akka-http using the source queue Implementation thread safe?

一个人想着一个人 提交于 2019-12-22 05:13:08
问题 Refering to the following implementation mentioned in: http://doc.akka.io/docs/akka-http/10.0.5/scala/http/client-side/host-level.html val poolClientFlow = Http().cachedHostConnectionPool[Promise[HttpResponse]]("akka.io") val queue = Source.queue[(HttpRequest, Promise[HttpResponse])](QueueSize, OverflowStrategy.dropNew) .via(poolClientFlow) .toMat(Sink.foreach({ case ((Success(resp), p)) => p.success(resp) case ((Failure(e), p)) => p.failure(e) }))(Keep.left) .run() Is it thread safe to offer

java.lang.NoSuchMethodError: akka.actor.ActorCell.addFunctionRef

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 20:30:05
问题 I am trying to setup a simple akka-http 2.4.2 project to test it out, but I am failing to do so. My built.sbt: import NativePackagerHelper._ lazy val akkaVersion = "2.4.2" lazy val root = (project in file(".")). settings( name := "akkTest", version := "0.1", scalaVersion := "2.11.7") libraryDependencies ++= Seq( "com.typesafe.akka" %% "akka-actor" % akkaVersion, "com.typesafe.akka" %% "akka-http-spray-json-experimental" % akkaVersion ) enablePlugins(JavaServerAppPackaging) my code snippet in

How to complete a request in another actor when using akka-http

醉酒当歌 提交于 2019-12-21 09:29:38
问题 I am using akka-http 1.0 and I would like to use a route defined as def route: Route = path("") { // start actor with requestContext // call requestContext.complete(...) in actor with the result } How do I accomplish this? 回答1: Elaborating on @jrudolph's comment, the below code satisfies your requirements of dispatching RequestContext values to an Actor. Your question indicated that you wanted a new Actor for each request; however, the below code uses the same Actor for all requests which I

Akka Stream + Akka Http - Get Request on Error

强颜欢笑 提交于 2019-12-21 06:06:27
问题 I have the following stream that works pretty well: source .map(x => HttpRequest(uri = x.rawRequest)) .via(Http().outgoingConnection(host, port)) .to(Sink.actorRef(myActor, IsDone)) .run() and a simple actor to handle the response status and the final message when the stream completes: /** * A simple actor to count how many rows have been processed * in the complete process given a http status * * It also finish the main thread upon a message of type [[IsDone]] is received */ class MyActor

Kubernetes - Akka clustering Deployment

末鹿安然 提交于 2019-12-21 05:06:37
问题 We have a docker image and a corresponding yaml file for the deployment using kubernetes. The application we have built is in scala with akka-http. We have used akka-cluster. We have a particular variable(seed-nodes in our case - akka cluster) in the configuration file which is used in our application code that uses the pod ip. But, we will not get the pod ip unless the deployment is done. How should we go about tackling the issue? Will environment variables help, if yes how? More