akka-http

How to use Akka-HTTP client websocket send message

℡╲_俬逩灬. 提交于 2019-12-04 14:07:17
问题 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

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

戏子无情 提交于 2019-12-04 12:43:50
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 Main.scala import akka.http.scaladsl.Http import akka.stream.ActorMaterializer import akka.stream

Kubernetes - Akka clustering Deployment

时光总嘲笑我的痴心妄想 提交于 2019-12-03 16:50:54
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 specifically, Once the docker images is deployed in the container in a pod, and when the container starts, the pod

Streaming file from server to client using Akka

徘徊边缘 提交于 2019-12-03 15:30:54
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()) } } } The Akka-Stream API allow you to create an entity directly out of a Source[ByteString, _] , so you can do something

How to handle response timeout?

非 Y 不嫁゛ 提交于 2019-12-03 15:00:49
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 Failure(result) => HttpResponse(entity = utils.getFault("fault")) }) future } Adding a timeout to an

AKKA-http deployment

一个人想着一个人 提交于 2019-12-03 14:22:06
This is the first time I'm working with akka-http. I wrote the following main class which starts the application: object Main extends App with Routes with Config with Protocols { implicit val system: ActorSystem = ActorSystem("slickboard-system") implicit val executor: ExecutionContext = system.dispatcher implicit val materializer: ActorMaterializer = ActorMaterializer() override val employeeActor: ActorRef = system.actorOf(EmployeeActor.props, "employees") val server = Http().bindAndHandle(route, httpServerURL, httpServerPort) } It starts a server on localhost, but when I try to deploy it on

How to properly call a single server from multiple actors / web handlers using Akka HTTP?

此生再无相见时 提交于 2019-12-03 13:37:07
I have a service (let's call it Service A) which uses Akka Server HTTP to handle incoming requests. Also I have 3rd party application (Service B) which provides several web services. The purpose of service A is to transform client requests, call one or multiple web services of service B, merge/transform results and serve it back to a client. I am using Actors for some parts, and just Future for other. To make a call to Service B, I use Akka HTTP client. Http.get(actorSystem).singleRequest(HttpRequest.create() .withUri("http://127.0.0.1:8082/test"), materializer) .onComplete(...) The issue is,

Akka Flow hangs when making http requests via connection pool

*爱你&永不变心* 提交于 2019-12-03 13:33:59
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 am I doing wrong ? import akka.actor.ActorSystem import akka.http.scaladsl.Http import akka.http

akka-http: How to set response headers

蓝咒 提交于 2019-12-03 12:55:04
I've a route as follows: val route = { logRequestResult("user-service") { pathPrefix("user") { get { respondWithHeader(RawHeader("Content-Type", "application/json")) { parameters("firstName".?, "lastName".?).as(Name) { name => findUserByName(name) match { case Left(users) => complete(users) case Right(error) => complete(error) } } } } ~ (put & entity(as[User])) { user => complete(Created -> s"Hello ${user.firstName} ${user.lastName}") } ~ (post & entity(as[User])) { user => complete(s"Hello ${user.firstName} ${user.lastName}") } ~ (delete & path(Segment)) { userId => complete(s"Hello $userId")

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