akka hello http server
所属分类 akka
浏览量 747
pom依赖
com.typesafe.akka:akka-http_2.13:10.1.15
com.typesafe.akka:akka-stream_2.13:2.6.18
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
import scala.io.StdIn
object HelloHttpServer {
def main(args: Array[String]): Unit = {
implicit val system = ActorSystem("hello-http-server")
implicit val materializer = ActorMaterializer()
implicit val executionContext = system.dispatcher
val route = path("hello") {
get {
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "hello akka-http"))
}
}
val port = 8888
val bingdingFuture = Http().bindAndHandle(route, "localhost", port)
println("akka hello http server start,port=" + port)
StdIn.readLine()
bingdingFuture.flatMap(_.unbind()).onComplete(_ => system.terminate())
}
}
http://127.0.0.1:8888/hello
mvn dependency:tree
[WARNING] The artifact xml-apis:xml-apis:jar:2.0.2 has been relocated to xml-apis:xml-apis:jar:1.0.b2
[INFO] com.dyyx:akka-http-hello:jar:1.0.0
[INFO] +- com.typesafe.akka:akka-http_2.13:jar:10.1.15:compile
[INFO] | +- org.scala-lang:scala-library:jar:2.13.7:compile
[INFO] | \- com.typesafe.akka:akka-http-core_2.13:jar:10.1.15:compile
[INFO] | \- com.typesafe.akka:akka-parsing_2.13:jar:10.1.15:compile
[INFO] \- com.typesafe.akka:akka-stream_2.13:jar:2.6.18:compile
[INFO] +- com.typesafe.akka:akka-actor_2.13:jar:2.6.18:compile
[INFO] | +- com.typesafe:config:jar:1.4.0:compile
[INFO] | \- org.scala-lang.modules:scala-java8-compat_2.13:jar:1.0.0:compile
[INFO] +- com.typesafe.akka:akka-protobuf-v3_2.13:jar:2.6.18:compile
[INFO] +- org.reactivestreams:reactive-streams:jar:1.0.3:compile
[INFO] \- com.typesafe:ssl-config-core_2.13:jar:0.4.2:compile
[INFO] \- org.scala-lang.modules:scala-parser-combinators_2.13:jar:1.1.2:compile
[INFO] ------------------------------------------------------------------------
org.scala-lang:scala-library:jar:2.13.7
com.typesafe.akka:akka-actor_2.13:jar:2.6.18
com.typesafe.akka:akka-http_2.13:jar:10.1.15
com.typesafe.akka:akka-http-core_2.13:jar:10.1.15
org.reactivestreams:reactive-streams:jar:1.0.3
com.typesafe.akka:akka-stream_2.13:jar:2.6.18
com.typesafe.akka:akka-parsing_2.13:jar:10.1.15
com.typesafe:config:jar:1.4.0
org.scala-lang.modules:scala-java8-compat_2.13:jar:1.0.0
com.typesafe.akka:akka-protobuf-v3_2.13:jar:2.6.18
com.typesafe:ssl-config-core_2.13:jar:0.4.2
org.scala-lang.modules:scala-parser-combinators_2.13:jar:1.1.2
完整代码
https://gitee.com/dyyx/hellocode/tree/master/demo/scala/akka-http-hello
上一篇
下一篇
scala 元组和多重赋值
play json 操作
play Application Settings
scala中的classOf isInstanceOf asInstanceOf
大数据scala基础
快学scala要点