Class: Vx::Lib::Consumer::Rpc::RpcProxy
- Inherits:
-
Object
- Object
- Vx::Lib::Consumer::Rpc::RpcProxy
- Defined in:
- lib/vx/lib/consumer/rpc.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #action(name, fn) ⇒ Object
- #call(method, args, options = {}) ⇒ Object
- #define ⇒ Object
-
#initialize(consumer) ⇒ RpcProxy
constructor
A new instance of RpcProxy.
- #process_payload(properties, payload) ⇒ Object
Constructor Details
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
18 19 20 |
# File 'lib/vx/lib/consumer/rpc.rb', line 18 def client @client end |
Instance Method Details
#action(name, fn) ⇒ Object
43 44 45 46 |
# 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 = {}) ⇒ Object
27 28 29 30 |
# File 'lib/vx/lib/consumer/rpc.rb', line 27 def call(method, args, = {}) ns = @parent.params.consumer_id @client.call ns, method, args, end |
#define ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# 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) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# 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 |