【发布时间】:2020-11-29 14:51:33
【问题描述】:
所以我正在尝试构建一个最小的 HTTP 服务器来接收 POST 请求,但我无法完成它,因为不知何故 Akka docs 上的示例无效,我无法从任何地方获取 executionContext。
这是我的代码:
object Main extends App {
implicit val system: ActorSystem = ActorSystem("server-system")
implicit val executionContext = system.executionContext // can't resolve symbol executionContext
// test route
val route =
path("test") {
get {
complete(HttpEntity(ContentTypes.`text/plain(UTF-8)`, "test"))
}
}
val address = "localhost"
val port = 8080
val bindingFuture = Http().newServerAt(address, port).bind(route)
println(s"Server online at $address:$port\nPress RETURN to stop...")
StdIn.readLine()
bindingFuture
.flatMap(_.unbind()) // no implicits found for parameter
.onComplete(_ => system.terminate()) // executor: ExecutorContext
}
我正在使用 10.2.1 版本,我正在使用 gradle 导入,如下所示:
compile group: 'com.typesafe.akka', name: "akka-http_2.12", version: "10.2.1"
compile group: 'com.typesafe.akka', name: "akka-stream_2.12", version: "2.6.8"
您是否有任何其他有效的快速入门示例,或任何其他更易于使用的库,以便像我尝试的那样设置一个非常小的服务器?
【问题讨论】:
标签: scala server akka dsl akka-http