Class: Nonnative::GRPCServer

Inherits:
Server show all
Defined in:
lib/nonnative/grpc_server.rb

Overview

gRPC server runner implemented using GRPC::RpcServer.

This is a convenience server implementation for running a gRPC service in-process under Nonnative’s server lifecycle. It binds to the configured proxy host/port and is started/stopped by Server via #perform_start / #perform_stop.

Important note about logging: the grpc gem uses a global logger. This implementation sets GRPC.logger to write to the configured service.log, and whichever gRPC server is initialized first “wins” that global logger.

See Also:

Instance Attribute Summary

Attributes inherited from Runner

#proxy

Instance Method Summary collapse

Methods inherited from Server

#start, #stop

Methods inherited from Runner

#name

Constructor Details

#initialize(svc, service) ⇒ GRPCServer

Creates a gRPC server and registers the provided service handler.

Parameters:

  • svc (Object)

    a gRPC service implementation (typically a ...::Service subclass instance)

  • service (Nonnative::ConfigurationServer)

    server configuration



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/nonnative/grpc_server.rb', line 20

def initialize(svc, service)
  @server = GRPC::RpcServer.new
  server.handle(svc)

  # Unfortunately gRPC has only one logger so the first server wins.
  GRPC.define_singleton_method(:logger) do
    @logger ||= Logger.new(service.log)
  end

  super(service)
end