Configuring Akka HTTP backend

Hello everyone,

We’re in the process of migration to Play 2.6 with its new Akka HTTP backend and I have a few inquiries concerning the backend configuration. Apparently there is no detailed documentation on this, I have only found it in pieces (not counting the Akka’s own docs):

Still, there’s no thorough list of what configuration keys are available and what are their purpose. And what irritates me the most is the fact that some configurations should be applied under “play.server.akka” namespace and some under “akka.http.server” - while this difference is never mentioned explicitly in the doc. Now, even when I’m willing to lookup some config in Akka’s own doc, I can’t be sure under which namespace I should put it in Play’s application.conf.

So, do I miss a page which I’m looking for or are there plans to prepare such a page? Currently it is too tedious to configure the backend correctly for the best performance.

Oh, and I’m using Java, not Scala. Though probably it’s not that important when talking about application.conf.

Hoping for your assistance. Thanks in advance!

2 Likes

Hi Sergey, thanks for posting the first message!

Here’s what you need to know, and I agree this should be added to the documentation.

Play’s embedded Akka ActorSystem reads its configuration from the configuration under akka. This is the default location used by Akka itself, and most of these settings are inherited from Akka’s default configuration. Akka HTTP will read its settings from akka.http, except for several settings that are patched by Play…

Play reads server backend settings from play.server.*. Settings under play.server.akka are specific to the Akka HTTP backend; settings under play.server.http are common to the Akka HTTP and Netty backends. Play uses these settings to override Akka HTTP or Netty’s default settings. So whatever is read from play.server will override any settings in akka.http.

There’s one additional wrinkle. When running in dev mode, i.e. when you use the run command in sbt, there can be more than one ActorSystem running at the same time. The server ActorSystem is started immediately. It listens to HTTP requests and then compiles and starts the user application - which has its own ActorSystem. The application ActorSystem is started and stopped whenever the application is restarted and recompiled, and it runs in a different ClassLoader to allow reloading.

In dev mode the application ActorSystem reads its configuration from akka and akka.http like usual. Unfortunately the server ActorSystem handling the HTTP requests needs to have different configuration so it reads its settings from play.akka.dev-mode and play.akka.dev-mode.http. In addition, this ActorSystem doesn’t have access to the application.conf due to the fact that it doesn’t share the application’s ClassLoader. So if you want to reconfigure Akka HTTP in dev mode you’ll need to do so via configuration in a JAR file.

Hope this helps,
Rich

7 Likes

Hi @scadge,

In addition to what @richdougherty said, there is also some specific documentation about Akka HTTP server backend:

  1. https://playframework.com/documentation/2.6.x/AkkaHttpServer

But yeah, we may need to improve that and make them more prominent.

3 Likes

Hi there,

We are basically having a similar issue.

Recently we decided to upgrade play framework from 2.4.x to 2.6.x

And when running on dev mode on the server box, we had this spool message keeps going, and the application simply not responding:

[WARN] [04/04/2018 10:55:14.501] [play-dev-mode-akka.actor.default-dispatcher-3] [akka.actor.ActorSystemImpl(play-dev-mode)] Illegal request, responding with status ‘400 Bad Request’: Request is missing required Host header: Cannot establish effective URI of request to /, request has a relative URI and is missing a Host header; consider setting akka.http.server.default-host-header

I have tried to set up the default-host-header for akka configuration, and just could not let the message disappeared. (I have tried play.server.akka.default-host-header as well as akka.http.server.default-host-header)

Suppose it has something to do with what @richdougherty mentioned in this post: the difference between running on dev mode and on prod mode.

I had a look at this post, and it mentioned the configuration is for HTTP/1.0 and HTTP/1.1 without a host header.
And I also did check that while our application running on play2.4.x, the HTTP version is already 1.1, so I guess it is the case that the ActorSystemImpl is processing requests without host header?

Our application is not really large size wise, and the configuration is not much, I am having no clue why it is all of the sudden need to have some extra configuration setup (and the configuration seems like a hack). I suspect it should be something really minor …

We also do have applications running on play2.6.x and without this issue…

Please help and let me know if you want me to post this as a separate topic, and if you need any more information such as config file…

Thank you in advance :slight_smile:

Cheers,
Rachel

@Rachel, if you want to pass settings to the reloadable server in dev mode use this approach in your build.sbt: https://www.playframework.com/documentation/2.6.x/ConfigFile#Extra-devSettings. To configure the server you may need to set akka.http.server.default-host-header or play.akka.dev-mode.http.server.default-host-header or both.

Thank you so much @richdougherty for your information, I did try both setup and no luck…

I will go back and have a look at my application.conf see if anything in the file mess up the application…

[Update]: Alright, the request is from our health check, and it was sending request using HTTP/1.0 and no header… After changed to HTTP/1.1 with a header, it works ok now.

1 Like

Good to hear!

2 Likes