Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.30 KB | None | 0 0
  1. package com.example.demo
  2.  
  3. import io.netty.handler.codec.http.HttpResponseStatus
  4. import reactor.core.publisher.Mono
  5. import reactor.netty.http.server.HttpServer
  6.  
  7.  
  8. class Application(val port: Int = 8080) {
  9.     private val server: HttpServer = HttpServer.create()
  10.  
  11.     fun start() {
  12.         server
  13.                 .port(port)
  14.                 .route {
  15.                     it.get("/test", { request, response ->
  16.                         println("A new request from ${request.remoteAddress().address}")
  17.                         val producer = Mono.fromCallable { "123" }
  18.  
  19.                         return@get response
  20.                                 .status(HttpResponseStatus.OK)
  21.                                 .sendString(producer)
  22.                     })
  23.  
  24.                     it.get("/test2", { request, response ->
  25.                         println("A new request from ${request.remoteAddress().address}")
  26.                         val producer = Mono.fromCallable { "456" }
  27.  
  28.                         return@get response
  29.                                 .status(HttpResponseStatus.OK)
  30.                                 .sendString(producer)
  31.                     })
  32.                 }.bind().subscribe({ }, { }, { })
  33.  
  34.         Thread.sleep(100000)
  35.     }
  36. }
  37.  
  38. fun main(args: Array<String>) {
  39.     Application().start()
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement