Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.demo
- import io.netty.handler.codec.http.HttpResponseStatus
- import reactor.core.publisher.Mono
- import reactor.netty.http.server.HttpServer
- class Application(val port: Int = 8080) {
- private val server: HttpServer = HttpServer.create()
- fun start() {
- server
- .port(port)
- .route {
- it.get("/test", { request, response ->
- println("A new request from ${request.remoteAddress().address}")
- val producer = Mono.fromCallable { "123" }
- return@get response
- .status(HttpResponseStatus.OK)
- .sendString(producer)
- })
- it.get("/test2", { request, response ->
- println("A new request from ${request.remoteAddress().address}")
- val producer = Mono.fromCallable { "456" }
- return@get response
- .status(HttpResponseStatus.OK)
- .sendString(producer)
- })
- }.bind().subscribe({ }, { }, { })
- Thread.sleep(100000)
- }
- }
- fun main(args: Array<String>) {
- Application().start()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement