Hi all, good day.
I would like to ask if someone know if its possible to run a ktor service with two different ports (and set of routes) so, for example, I can have the metrics scrapper running on a separate port) .
I tried looking at the docs but could not figure out a way of doing that.
s
simon.vergauwen
07/04/2022, 8:11 AM
Afaik you should be able to spin up 2x
embeddedServer
using the
Netty
engine but bound to different ports.
For example:
Copy code
fun main() = runBlocking<Unit> {
launch {
embeddedServer(Netty, port = 8080) {
// install routes
}
}
launch {
embeddedServer(Netty, port = 8081) {
// install other routes
}
}
}
simon.vergauwen
07/04/2022, 8:12 AM
If that doesn't work
embeddedServer
I'd consider it bugged.
f
fbodr
07/04/2022, 8:16 AM
is it possible using HOCON configuration file instead of code ?
a
Aleksei Tirman [JB]
07/04/2022, 8:37 AM
Also, you can configure multiple ports for the same server instance and match routes by a specific port. Unfortunately, you can’t configure it via a configuration file.
Copy code
embeddedServer(Netty, applicationEngineEnvironment {
connector {
port = 8080
}
connector {
port = 8081
}
module {
routing {
port(8081) {
get {
}
}
}
}
}).start()
f
fbodr
07/04/2022, 8:39 AM
yes, thats exactly what I want… mmm.. but no configuration file is a bummer 😫