class Vx::Lib::Consumer::Rpc::RpcProxy
Attributes
client[R]
Public Class Methods
new(consumer)
click to toggle source
# File lib/vx/lib/consumer/rpc.rb, line 20 def initialize(consumer) @parent = consumer @client = RpcClient.new consumer @methods = {} @defined = false end
Public Instance Methods
action(name, fn)
click to toggle source
# File lib/vx/lib/consumer/rpc.rb, line 43 def action(name, fn) define unless @defined @methods[name.to_s] = fn end
call(method, args, options = {})
click to toggle source
# File lib/vx/lib/consumer/rpc.rb, line 27 def call(method, args, options = {}) ns = @parent.params.consumer_id @client.call ns, method, args, options end
define()
click to toggle source
# File lib/vx/lib/consumer/rpc.rb, line 32 def define @parent.exchange RPC_EXCHANGE_NAME @parent.queue "vx.rpc.#{@parent.params.consumer_id}".freeze, durable: false, auto_delete: true @parent.send :define_method, :perform do |payload| self.class.rpc.process_payload(properties, payload) end @defined = true end
process_payload(properties, payload)
click to toggle source
# File lib/vx/lib/consumer/rpc.rb, line 48 def process_payload(properties, payload) m = payload[RPC_PAYLOAD_METHOD] p = payload[RPC_PAYLOAD_PARAMS] if fn = @methods[m] re = fn.call(*p) @parent.publish( { 'result' => re }, routing_key: properties[:reply_to], correlation_id: properties[:correlation_id], content_type: JSON_CONTENT_TYPE ) end end