class RPCBench::RabbitMQ::Server

Public Class Methods

new(opts) click to toggle source
# File lib/rpc_bench/driver_rabbitmq.rb, line 41
def initialize opts
  @opts = opts
end

Public Instance Methods

run() click to toggle source
# File lib/rpc_bench/driver_rabbitmq.rb, line 45
def run
  conn = Bunny.new(host: @opts[:host], port: @opts[:port])
  conn.start

  ch = conn.create_channel

  queue = ch.queue RPCBench::RabbitMQ::QNAME
  exchange = ch.default_exchange
  queue.subscribe(:block => true) do |_, attr, data|
    resp = @handler.callback(data.to_i)

    exchange.publish(resp.to_s, :routing_key => attr.reply_to, :correlation_id => attr.correlation_id)
  end

  ch.close
  conn.close
end