1

I'm trying to embed an akka-http server into my ammonite scala script.

Below is the scala code used to create a server instance

import ammonite.ops._

import $ivy.`com.typesafe:config:1.3.1`
import $ivy.`com.typesafe.akka:akka-http_2.12:10.0.6`
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import com.typesafe.config.ConfigFactory
import java.io._

@main
def main() = {
  val fileConfig = ConfigFactory.parseFile(new File("resources/my.conf"))
  val config = ConfigFactory.load(fileConfig)

  println(config)

  implicit val actorSystem = ActorSystem("system")
  implicit val actorMaterializer = ActorMaterializer()

  val route =
    pathSingleSlash {
      get {
        complete {
          "Hello world"
        }
      }
    }
  Http().bindAndHandle(route,"localhost",8080)
  println("server started at 8080")
}

Here is the my.conf file content:

akka {
  loglevel = INFO
  stdout-loglevel = INFO
  default-dispatcher {
    fork-join-executor {
      parallelism-min = 8
    }
}

Running the script with amm server.sc I got the following error:

Exception in thread "main" com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka'

The same happen with the standard application.conf filename convention too.

I can read the file and get the content correctly. What I'm missing?

Thanks a lot

mvito
  • 75
  • 3

1 Answers1

1

You need to pass the config to the ActorSystem like ActorSystem("system", config)

Stephen
  • 4,228
  • 4
  • 29
  • 40
  • thanks a lot, helpful. Why it is looking now for the entire set of configuration options for akka? (e.g. loggers-dispatcher, serialize-messages, unstarted-push-timeout, ....) If i do not provide the entire set, it does not work – mvito May 11 '17 at 12:39