Skip to content

Instantly share code, notes, and snippets.

@viggin543
Created April 17, 2020 18:29
Show Gist options
  • Save viggin543/659c658e805389d6e431316073d3575c to your computer and use it in GitHub Desktop.
Save viggin543/659c658e805389d6e431316073d3575c to your computer and use it in GitHub Desktop.
a simple vert.x/netty web server written in kotlin
import io.vertx.core.Vertx
import io.vertx.ext.web.Router
import java.time.Instant.now
import kotlin.math.pow
fun main() {
println("starting application ${now().epochSecond}")
val now = now()
val cores = Runtime.getRuntime().availableProcessors()
val ram = Runtime.getRuntime().maxMemory().toDouble()
println("starting app on cpu with $cores cores and ram ${ram / 2.0.pow(30.0)} GB")
val vertx = Vertx.vertx()
vertx.createHttpServer()
.requestHandler(Router.router(vertx).apply {
val alive by lazy { println("im alive ${now().epochSecond}") }
get("/system/health/liveness").handler { ctx ->
alive
ctx.response().end()
}
val ready by lazy { println("im ready ${now().epochSecond}") }
get("/system/health/readiness").handler { ctx ->
ready
ctx.response().end()
}
}).listen(8080) { server ->
when {
server.failed() -> println("failed to start server")
else -> println("http server is up and running on port 8080 ${now().epochSecond - now.epochSecond} seconds")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment