1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#!/usr/bin/env ruby
require 'bunny'
conn = Bunny.new
conn.start
ch = conn.create_channel
ch.confirm_select
q1 = ch.queue("q1", durable: true)
q2 = ch.queue("q2", durable: true)
q3 = ch.queue("q3", durable: true)
q4 = ch.queue("q4", durable: true)
[q1, q2, q3, q4]. each(&:purge)
x = ch.exchange("chx", type: "x-consistent-hash", durable: true)
[q1, q2].each { |q| q.bind(x, routing_key: "1") }
[q3, q4].each { |q| q.bind(x, routing_key: "2") }
n = 100_000
n.times do |i|
x.publish(i.to_s, routing_key: i.to_s)
end
ch.wait_for_confirms
puts "Done publishing!"
# wait for queue stats to be emitted so that management UI numbers
# are up-to-date
sleep 5
conn.close
puts "Done"
|