Class: Gruf::Server

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/gruf/server.rb

Overview

Represents a gRPC server. Automatically loads and augments gRPC handlers and services based on configuration values.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Loggable

#logger

Constructor Details

#initialize(services: []) ⇒ Server

Initialize the server and load and setup the services

Parameters:

  • services (Array<Class>) (defaults to: [])

    The services that this server should handle



33
34
35
36
# File 'lib/gruf/server.rb', line 33

def initialize(services: [])
  setup!
  load_services(services)
end

Instance Attribute Details

#servicesArray<Class>

Returns The services this server is handling.

Returns:

  • (Array<Class>)

    The services this server is handling



26
27
28
# File 'lib/gruf/server.rb', line 26

def services
  @services
end

Instance Method Details

#start!Object

Start the gRPC server

:nocov:



42
43
44
45
46
47
48
49
50
51
# File 'lib/gruf/server.rb', line 42

def start!
  logger.info { 'Booting gRPC Server...' }
  server = GRPC::RpcServer.new
  server.add_http2_port Gruf.server_binding_url, ssl_credentials
  services.each do |s|
    server.handle(s)
  end
  server.run_till_terminated
  logger.info { 'Shutting down gRPC server...' }
end