标签:http bsp util stat actor col sys fun mat
AKKA HTTP 简单示例
依赖包:
compile("com.typesafe.akka:akka-http_2.13:10.1.8")
compile("com.typesafe.akka:akka-stream_2.13:2.5.23")
代码示例:
package http import akka.actor.ActorSystem import akka.http.javadsl.server.HttpApp import akka.http.javadsl.server.Route import akka.stream.Server import java.util.function.Supplier import akka.http.javadsl.ConnectHttp import akka.http.javadsl.Http import akka.http.javadsl.model.HttpResponse import akka.http.javadsl.model.StatusCodes import java.util.concurrent.CompletionStage import akka.stream.ActorMaterializer /** * Created by: tankx * Date: 2019/7/16 * Description: */ class HelloHttp constructor() : HttpApp() { override fun routes(): Route { return createRoute() } private fun createRoute(): Route { val path = path("hello", object : Supplier<Route> { override fun get(): Route { return complete("Say hello to akka-http") } }) return concat(path) } } fun main() { // boot up server using the route as defined below //val system = ActorSystem.create("routes") HelloHttp().startServer("localhost", 8888) }
启动后访问地址 http://127.0.0.1:8888/hello
返回Say hello to akka-http
标签:http bsp util stat actor col sys fun mat
原文地址:https://www.cnblogs.com/tankaixiong/p/11194061.html