Configures and starts a gRPC server within the Ktor application. This function integrates with the Ktor lifecycle and manages the lifecycle of the gRPC server by subscribing to ApplicationStopping and ApplicationStopped events. It ensures that a gRPC server is properly initialized, started, and shutdown when the application stops.
Usage:
fun Application.module() {
grpc(port = PORT) {
services {
registerService<MyService> { MyServiceImpl() }
}
}
}Return
The instance of the initialized and running GrpcServer.
Parameters
The port on which the gRPC server will listen for incoming connections. Defaults to the value specified in the ktor.deployment.grpcPort configuration, or 8001 if not configured.
Allows additional configuration of the gRPC server using a GrpcServerConfiguration.
Throws
if a gRPC server is already installed, or the specified port conflicts with an existing HTTP/HTTPS server port.