class RPCBench::RabbitMQ::Client
Public Class Methods
new(opts)
click to toggle source
# File lib/rpc_bench/driver_rabbitmq.rb, line 8 def initialize opts @opts = opts end
Public Instance Methods
send_request(data, count)
click to toggle source
# 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