Class: Lagomorph::RpcCall

Inherits:
Object
  • Object
show all
Defined in:
lib/lagomorph/rpc_call.rb

Instance Method Summary collapse

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_channelObject



30
31
32
33
34
# File 'lib/lagomorph/rpc_call.rb', line 30

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
# 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)

  response['result'] || fail(RpcError, response.fetch('error'))
end