Microservices
Standalone applications
Use the container without a web server: workers, scripts and command-line tools.
You do not need a web server to use Kest. A standalone application builds the container (so you get dependency injection, configuration, the database, queues, schedules) and does not start HTTP.
fun main() {
val app = Kest.create<AppModule>() // build every provider; no web server
app.get(ReportService::class).sendDailyReport() // use any provider
app.close() // run the shutdown hooks and exit
}Kest.create only builds the container. Kest.run does the same and also logs the start-up and registers a shutdown hook, which is what a long-running process wants.
Three common shapes
1. A script or one-off job (a data migration, a report): create, do the work, close, exit, as above.
2. A worker that processes queue jobs, runs scheduled tasks and handles events, with no HTTP:
fun main(args: Array<String>) {
Kest.run<WorkerModule>(args) // queue processors and @Cron jobs start with the container
Thread.currentThread().join() // keep the process alive
}Run several of them to add capacity: queue jobs are shared among workers, and locks keep a scheduled job to one at a time. kest new --template worker creates this layout.
3. A command-line tool with arguments and sub-commands: see Commander.
Hybrid applications
One container can serve HTTP and consume messages: app.http(...) and app.microservice(...) on the same Kest.run (Hybrid application).
In tests
Testing.createModule<AppModule>() is a standalone container with overrides (Testing).