Class: CarrotRpc::RpcServer
- Inherits:
-
Object
- Object
- CarrotRpc::RpcServer
- Extended by:
- ClientServer
- Includes:
- Reply
- Defined in:
- lib/carrot_rpc/rpc_server.rb
Overview
Base RPC Server class. Other Servers should inherit from this.
Defined Under Namespace
Modules: JSONAPIResources
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#server_queue ⇒ Object
readonly
Returns the value of attribute server_queue.
-
#thread_request_variable ⇒ Object
readonly
Returns the value of attribute thread_request_variable.
Instance Method Summary collapse
-
#initialize(config: nil, block: true) ⇒ RpcServer
constructor
Documentation advises not to share a channel connection.
- #process_request(request_message, properties:) ⇒ Object
-
#start ⇒ Object
start da server! method => object that receives the method.
Methods included from ClientServer
queue_name, queue_options, test_queue_name
Constructor Details
#initialize(config: nil, block: true) ⇒ RpcServer
Documentation advises not to share a channel connection. Create new channel for each server instance.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/carrot_rpc/rpc_server.rb', line 14 def initialize(config: nil, block: true) # create a channel and exchange that both client and server know about config ||= CarrotRpc.configuration @thread_request_variable = config.thread_request_variable @channel = config.bunny.create_channel @logger = config.logger @block = block setup_queue(config) @exchange = @channel.default_exchange end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
7 8 9 |
# File 'lib/carrot_rpc/rpc_server.rb', line 7 def channel @channel end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/carrot_rpc/rpc_server.rb', line 7 def logger @logger end |
#server_queue ⇒ Object (readonly)
Returns the value of attribute server_queue.
7 8 9 |
# File 'lib/carrot_rpc/rpc_server.rb', line 7 def server_queue @server_queue end |
#thread_request_variable ⇒ Object (readonly)
Returns the value of attribute thread_request_variable.
7 8 9 |
# File 'lib/carrot_rpc/rpc_server.rb', line 7 def thread_request_variable @thread_request_variable end |
Instance Method Details
#process_request(request_message, properties:) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/carrot_rpc/rpc_server.rb', line 34 def process_request(, properties:) maybe_thread_request(request_message: ) do method = [:method] handler = method_handler(method) send handler, method: method, properties: properties, request_message: end end |
#start ⇒ Object
start da server! method => object that receives the method. can be a class or anything responding to send
27 28 29 30 31 32 |
# File 'lib/carrot_rpc/rpc_server.rb', line 27 def start # subscribe is like a callback @server_queue.subscribe(block: @block) do |delivery_info, properties, payload| consume(delivery_info, properties, payload) end end |