class GRPC::Server

Overview

Server hosts registered gRPC services and dispatches incoming RPCs.

Plain TCP example: server = GRPC::Server.new server.handle GreeterImpl.new server.listen "0.0.0.0", 50051

TLS example: server = GRPC::Server.new server.use_tls(cert: "server.crt", key: "server.key") server.handle GreeterImpl.new server.listen "0.0.0.0", 50051

Defined in:

grpc/server.cr

Constant Summary

LOGGER = ::Log.for(self)

Constructors

Instance Method Summary

Constructor Detail

def self.new(transport_factory : ServerTransportFactory | Nil = nil) #

[View source]

Instance Method Detail

def bind(address : String) : self #

bind sets up the TCP listener without starting the serve loop. Call serve (or start for non-blocking) afterward.


[View source]
def enable_health_checking(default_status : Grpc::Health::V1::HealthCheckResponse::ServingStatus = ::Grpc::Health::V1::HealthCheckResponse::ServingStatus::SERVING) : Health::Reporter #

enable_health_checking registers the built-in health service and returns its reporter. Calling this multiple times returns the same instance.


[View source]
def enable_reflection : Reflection::Service #

enable_reflection registers the built-in reflection service and returns it. Register FileDescriptorProto bytes on the returned service via add_file_descriptor.


[View source]
def handle(service : Service) : self #

handle registers a service implementation with the server.


[View source]
def intercept(interceptor : ServerInterceptor) : self #

intercept registers a server-side interceptor. Interceptors run outermost-first (first registered wraps all others). Must be called before listen/bind.


[View source]
def listen(host : String, port : Int32) : Nil #

listen binds to the given host and port and starts serving. Blocks until stopped.


[View source]
def listen(host : String, port : String) : Nil #

listen with port as a string.


[View source]
def listen(address : String) : Nil #

listen with a combined "host:port" address string.


[View source]
def reflection_service? : Reflection::Service | Nil #

Returns the registered reflection service if enabled.


[View source]
def serve : Nil #

serve starts the accept loop. Blocks until stopped.


[View source]
def start : Nil #

start runs the server in a background fiber, returning immediately. Useful for tests and embedded servers.


[View source]
def stop : Nil #

[View source]
def use_tls(cert : String, key : String) : self #

use_tls configures the server to accept TLS connections. cert is the path to the PEM-encoded certificate chain file. key is the path to the PEM-encoded private key file. Must be called before listen/bind.


[View source]
def use_tls(context : OpenSSL::SSL::Context::Server) : self #

use_tls with a pre-built OpenSSL context for full control over TLS settings.


[View source]