Class: Gruf::Server
Overview
Represents a gRPC server. Automatically loads and augments gRPC handlers and services based on configuration values.
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
Hash of options passed into the server.
-
#port ⇒ Integer
readonly
The port the server is bound to.
-
#server ⇒ GRPC::RpcServer
readonly
The GRPC server running.
Instance Method Summary collapse
-
#add_interceptor(klass, opts = {}) ⇒ Object
Add an interceptor to the server.
- #add_service(klass) ⇒ Object
-
#initialize(options = {}) ⇒ Server
constructor
Initialize the server and load and setup the services.
-
#start! ⇒ Object
Start the gRPC server.
Methods included from Loggable
Constructor Details
#initialize(options = {}) ⇒ Server
Initialize the server and load and setup the services
37 38 39 40 41 42 43 |
# File 'lib/gruf/server.rb', line 37 def initialize( = {}) @options = || {} @interceptors = .fetch(:interceptor_registry, Gruf.interceptors) @interceptors = Gruf::Interceptors::Registry.new unless @interceptors.is_a?(Gruf::Interceptors::Registry) @services = [] setup! end |
Instance Attribute Details
#options ⇒ Hash (readonly)
Returns Hash of options passed into the server.
30 31 32 |
# File 'lib/gruf/server.rb', line 30 def @options end |
#port ⇒ Integer (readonly)
Returns The port the server is bound to.
28 29 30 |
# File 'lib/gruf/server.rb', line 28 def port @port end |
#server ⇒ GRPC::RpcServer (readonly)
Returns The GRPC server running.
26 27 28 |
# File 'lib/gruf/server.rb', line 26 def server @server end |
Instance Method Details
#add_interceptor(klass, opts = {}) ⇒ Object
Add an interceptor to the server
81 82 83 |
# File 'lib/gruf/server.rb', line 81 def add_interceptor(klass, opts = {}) @interceptors.use(klass, opts) end |
#add_service(klass) ⇒ Object
71 72 73 |
# File 'lib/gruf/server.rb', line 71 def add_service(klass) @services << klass unless @services.include?(klass) end |
#start! ⇒ Object
Start the gRPC server
:nocov:
61 62 63 64 65 |
# File 'lib/gruf/server.rb', line 61 def start! logger.info { 'Booting gRPC Server...' } server.run_till_terminated logger.info { 'Shutting down gRPC server...' } end |