Skip to content

Instantly share code, notes, and snippets.

@michaelklishin

michaelklishin/Gemfile Secret

Created May 3, 2013
Embed
What would you like to do?
source "https://rubygems.org"
gem "bunny", :git => "git://github.com/ruby-amqp/bunny.git"
#!/usr/bin/env ruby
require 'bunny'
Bundler.setup
connection = Bunny.new
connection.start
# ch = Bunny::Channel.new(connection, nil, Bunny::ConsumerWorkPool.new(8))
# ch.open
ch = connection.create_channel
def in_kb(n)
(n / 1024).round(2)
end
q = ch.queue("bunny.issues.119.limited", :durable => true, :arguments => {"x-max-length" => 100})
# q = ch.queue("bunny.issues.119", :durable => true)
begin
ts = []
3.times do |i|
q.subscribe(:block => false) do |delivery_info, metadata, payload|
puts "Consumer #{delivery_info.consumer_tag} consumed #{in_kb(payload.bytesize)} KB"
end
end
q.subscribe(:block => true) do |delivery_info, metadata, payload|
puts "Consumer #{delivery_info.consumer_tag} consumed #{in_kb(payload.bytesize)} KB"
end
rescue Interrupt => e
puts "Terminating..."
connection.close
end
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'bunny'
Bundler.setup
connection = Bunny.new
connection.start
ch = connection.channel
x = ch.default_exchange
def multiplier(a, b)
Range.new(a, b).to_a.sample
end
begin
ts = []
4.times do |i|
t = Thread.new do
loop do
puts "Publishing on thread #{i}"
10.times do |i|
n = multiplier(1, 1536) * 128
msg = "Юникодный юникод такой юникодный #{i}" * n
x.publish(msg, :routing_key => "bunny.issues.119.limited")
end
sleep (5.0 * rand)
end
end
t.abort_on_exception = true
ts << t
end
ts.each { |t| t.join }
rescue Interrupt => e
puts "Terminating..."
connection.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment