Add an URL for shutting down the server

预计阅读时间:1分钟

此功能启用URL,该URL在被访问时将关闭服务器.

有两种使用方式: 自动使用HOCON安装功能

此功能定义在类io.ktor.server.engine.ShutDownUrl.ApplicationCallFeature在神器io.ktor:ktor-server-host-common:$ktor_version .
dependencies { implementation "io.ktor:ktor-server-host-common:$ktor_version" }
dependencies { implementation("io.ktor:ktor-server-host-common:$ktor_version") }
<project> ... <dependencies> <dependency> <groupId>io.ktor</groupId> <artifactId>ktor-server-host-common</artifactId> <version>${ktor.version}</version> <scope>compile</scope> </dependency> </dependencies> </project>

Automatically using HOCON

您可以使用带有ktor.deployment.shutdown.url属性的HOCON来配置关闭URL.

ktor {
    deployment {
        shutdown.url = "/my/shutdown/path"
    }
}

Installing the feature

您可以使用ShutDownUrl.ApplicationCallFeature手动安装该功能,并设置shutDownUrlexitCodeSupplier

install(ShutDownUrl.ApplicationCallFeature) {
    // The URL that will be intercepted
    shutDownUrl = "/ktor/application/shutdown"
    // A function that will be executed to get the exit code of the process
    exitCodeSupplier = { 0 } // ApplicationCall.() -> Int
}

by  ICOPY.SITE