Class: Lagomorph::RpcCall
- Inherits:
-
Object
- Object
- Lagomorph::RpcCall
- Defined in:
- lib/lagomorph/rpc_call.rb
Instance Method Summary collapse
- #close_channel ⇒ Object
- #dispatch(queue_name, method, *params) ⇒ Object
-
#initialize(session) ⇒ RpcCall
constructor
A new instance of RpcCall.
Constructor Details
#initialize(session) ⇒ RpcCall
Returns a new instance of RpcCall.
8 9 10 11 12 |
# File 'lib/lagomorph/rpc_call.rb', line 8 def initialize(session) @session = session @results = {} @mutex = Monitor.new end |
Instance Method Details
#close_channel ⇒ Object
34 35 36 37 38 |
# File 'lib/lagomorph/rpc_call.rb', line 34 def close_channel return unless @prepared_channel @channel.close @prepared_channel = false end |
#dispatch(queue_name, method, *params) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lagomorph/rpc_call.rb', line 14 def dispatch(queue_name, method, *params) @queue_name = queue_name correlation_id = calculate_correlation_id @mutex.synchronize do @results[correlation_id] = ::Queue.new end prepare_channel payload = prepare_payload(method, *params) publish_rpc_call(payload, correlation_id) response = block_till_receive_response(correlation_id) if response.key?('result') response['result'] else fail(RpcError, response.fetch('error', 'Unknown error')) end end |