码迷,mamicode.com
首页 > Web开发 > 详细

AKKA HTTP 简单示例

时间:2019-07-16 12:35:46      阅读:127      评论:0      收藏:0      [点我收藏+]

标签: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

 

AKKA HTTP 简单示例

标签:http   bsp   util   stat   actor   col   sys   fun   mat   

原文地址:https://www.cnblogs.com/tankaixiong/p/11194061.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!