此功能启用URL,该URL在被访问时将关闭服务器.
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>
您可以使用带有ktor.deployment.shutdown.url属性的HOCON来配置关闭URL.
ktor {
deployment {
shutdown.url = "/my/shutdown/path"
}
}
您可以使用ShutDownUrl.ApplicationCallFeature
手动安装该功能,并设置shutDownUrl
和exitCodeSupplier
:
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
}