grpc

Available in a dev version: 0․11․0-grpc-186

How to configure

fun Application.grpc(port: Int = environment.config.propertyOrNull(GrpcConfigKeys.grpcHostPortPath)?.getAs<Int>() ?: 8001, configure: GrpcServerConfiguration.() -> Unit = {}): GrpcServer(source)

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

port

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.

configure

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.