Class: SneakersPacker::RpcClient
- Inherits:
-
Object
- Object
- SneakersPacker::RpcClient
- Defined in:
- lib/sneakers_packer/rpc_client.rb
Instance Attribute Summary collapse
-
#call_id ⇒ Object
Returns the value of attribute call_id.
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#lock ⇒ Object
readonly
Returns the value of attribute lock.
-
#reply_queue ⇒ Object
readonly
Returns the value of attribute reply_queue.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
-
#call(name, message, options = {}) ⇒ Object
call remote service via rabbitmq rpc.
-
#initialize(publisher) ⇒ RpcClient
constructor
A new instance of RpcClient.
Constructor Details
#initialize(publisher) ⇒ RpcClient
Returns a new instance of RpcClient.
8 9 10 11 12 |
# File 'lib/sneakers_packer/rpc_client.rb', line 8 def initialize(publisher) @publisher = publisher channel, exchange = fetch_channel_and_exchange @consumer = build_reply_queue(channel, exchange) end |
Instance Attribute Details
#call_id ⇒ Object
Returns the value of attribute call_id.
5 6 7 |
# File 'lib/sneakers_packer/rpc_client.rb', line 5 def call_id @call_id end |
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
6 7 8 |
# File 'lib/sneakers_packer/rpc_client.rb', line 6 def condition @condition end |
#lock ⇒ Object (readonly)
Returns the value of attribute lock.
6 7 8 |
# File 'lib/sneakers_packer/rpc_client.rb', line 6 def lock @lock end |
#reply_queue ⇒ Object (readonly)
Returns the value of attribute reply_queue.
4 5 6 |
# File 'lib/sneakers_packer/rpc_client.rb', line 4 def reply_queue @reply_queue end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/sneakers_packer/rpc_client.rb', line 5 def response @response end |
Instance Method Details
#call(name, message, options = {}) ⇒ Object
call remote service via rabbitmq rpc
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sneakers_packer/rpc_client.rb', line 20 def call(name, , = {}) self.call_id = SecureRandom.uuid self.response = nil ensure_reply_queue! @exchange.publish(.to_s, routing_key: name.to_s, correlation_id: call_id, reply_to: @reply_queue.name) timeout = ([:timeout] || SneakersPacker.conf.rpc_timeout).to_i lock.synchronize { condition.wait(lock, timeout) } if response response else raise RemoteCallTimeoutError.new("远程调用超时") end end |