Here is a silly question.... can Ktor Server be ma...
# ktor
a
Here is a silly question.... can Ktor Server be made into a more generic (server) application runtime? I really like the way Ktor is configurable and extendable and a lot of things aren't necessarily HTTP-server related: config management, application parameters, DI, plugins, App lifecycle events. In that sense the http-server can also be a plugin? Out of the box Ktor has some pretty nice ways of setting up and configuring your app. The reason I was thinking about this is that I was adding a simple kafka consumer in my app using a plugin and the plugin system and DI made that very ergonomic:
Copy code
fun Application.module(myService: MyService) {
    subscribe(topic = "my-topic", autoOffsetReset = Latest) {
         on<UserRegistered> { event ->
            myService.userHasRegistered(event.user)
         }
    }
}
No need for HTTP (although I use it for liveness and readyness probe) but I use al the Ktor app features
👍 1
b
I'm not sure if there's a validation check in place, but in theory you could create a server with no connectors, which would be like an HTTP server that listens to nothing. You can also use unix sockets too if you just want to avoid using the network. In general though, there's no abstraction layer between Application <-> HTTP Server in Ktor. Interesting idea though, I'll have to think about it 😄
a
For me Ktor is such a delight to develop in, and I now am using it for small backend services that require no HTTP at all. Organizing modules with DI and configurations is such a great way to develop apps. We also have a NodeJS stack where we use NestJS (not NextJs) and they allow building microservices with another transport layer. So no HTTP, but NATS for instance. You still have a server, but it does not have to be HTTP.
r
I had a similar use-case for a MCP server in stdio mode (using the kotlin SDK). I'm doing it manually for now but using Ktor's config parsing - it would be even nicer to be able to do something like what is described here
a
This is a cool idea. I’ve been thinking about trying to build some kind of general purpose app framework for Kotlin. And figured Ktor was a good choice for the web layer, but actually it might already be usable as the whole framework. There isn’t necessarily anything web specific about a lot of it.
b
I've logged a ticket to look into it for 4.0.0 https://youtrack.jetbrains.com/issue/KTOR-9080/Reuseable-Ktor-application-framework-abstraction Sounds like it could have some utility 👍
a
Awesome! I was just think about creating a ticket for it