Class: RPCBench::RabbitMQ::Client
- Defined in:
- lib/rpc_bench/driver_rabbitmq.rb
Instance Method Summary collapse
-
#initialize(opts) ⇒ Client
constructor
A new instance of Client.
- #send_request(data, count) ⇒ Object
Methods inherited from Driver
Constructor Details
#initialize(opts) ⇒ Client
Returns a new instance of Client.
8 9 10 |
# File 'lib/rpc_bench/driver_rabbitmq.rb', line 8 def initialize opts @opts = opts end |
Instance Method Details
#send_request(data, count) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rpc_bench/driver_rabbitmq.rb', line 12 def send_request data, count results = [] conn = Bunny.new(host: @opts[:host], port: @opts[:port]) conn.start ch = conn.create_channel exchange = ch.default_exchange reply_queue = ch.queue("", :exclusive => true) (1..count).each do |_| exchange.publish(data.to_s, :routing_key => RPCBench::RabbitMQ::QNAME, :reply_to => reply_queue.name) end reply_queue.subscribe(:block => true) do |dinfo, _, data| results << data.to_i if results.size >= count dinfo.consumer.cancel break end end ch.close conn.close results end |