bunny 2.17.0 → 2.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/bunny/session.rb +22 -4
- data/lib/bunny/transport.rb +7 -6
- data/lib/bunny/version.rb +1 -1
- data/spec/higher_level_api/integration/basic_consume_spec.rb +14 -6
- data/spec/higher_level_api/integration/tls_connection_spec.rb +25 -32
- data/spec/issues/issue609_spec.rb +84 -0
- data/spec/lower_level_api/integration/basic_cancel_spec.rb +1 -1
- data/spec/lower_level_api/integration/basic_consume_spec.rb +8 -8
- metadata +28 -87
- data/.github/ISSUE_TEMPLATE.md +0 -18
- data/.gitignore +0 -28
- data/.rspec +0 -1
- data/.travis.yml +0 -33
- data/.yardopts +0 -8
- data/CONTRIBUTING.md +0 -132
- data/ChangeLog.md +0 -2129
- data/Gemfile +0 -55
- data/LICENSE +0 -21
- data/Rakefile +0 -54
- data/benchmarks/basic_publish/with_128K_messages.rb +0 -35
- data/benchmarks/basic_publish/with_1k_messages.rb +0 -35
- data/benchmarks/basic_publish/with_4K_messages.rb +0 -35
- data/benchmarks/basic_publish/with_64K_messages.rb +0 -35
- data/benchmarks/channel_open.rb +0 -28
- data/benchmarks/mutex_and_monitor.rb +0 -42
- data/benchmarks/queue_declare.rb +0 -29
- data/benchmarks/queue_declare_and_bind.rb +0 -29
- data/benchmarks/queue_declare_bind_and_delete.rb +0 -29
- data/benchmarks/synchronized_sorted_set.rb +0 -53
- data/benchmarks/write_vs_write_nonblock.rb +0 -49
- data/bunny.gemspec +0 -34
- data/docker-compose.yml +0 -28
- data/docker/Dockerfile +0 -24
- data/docker/apt/preferences.d/erlang +0 -3
- data/docker/apt/sources.list.d/bintray.rabbitmq.list +0 -2
- data/docker/docker-entrypoint.sh +0 -26
- data/docker/rabbitmq.conf +0 -29
- data/examples/connection/authentication_failure.rb +0 -16
- data/examples/connection/automatic_recovery_with_basic_get.rb +0 -40
- data/examples/connection/automatic_recovery_with_client_named_queues.rb +0 -36
- data/examples/connection/automatic_recovery_with_multiple_consumers.rb +0 -46
- data/examples/connection/automatic_recovery_with_republishing.rb +0 -109
- data/examples/connection/automatic_recovery_with_server_named_queues.rb +0 -35
- data/examples/connection/channel_level_exception.rb +0 -27
- data/examples/connection/disabled_automatic_recovery.rb +0 -34
- data/examples/connection/heartbeat.rb +0 -17
- data/examples/connection/manually_reconnecting_consumer.rb +0 -23
- data/examples/connection/manually_reconnecting_publisher.rb +0 -28
- data/examples/connection/unknown_host.rb +0 -16
- data/examples/consumers/high_and_low_priority.rb +0 -50
- data/examples/guides/exchanges/direct_exchange_routing.rb +0 -36
- data/examples/guides/exchanges/fanout_exchange_routing.rb +0 -28
- data/examples/guides/exchanges/headers_exchange_routing.rb +0 -31
- data/examples/guides/exchanges/mandatory_messages.rb +0 -30
- data/examples/guides/extensions/alternate_exchange.rb +0 -30
- data/examples/guides/extensions/basic_nack.rb +0 -33
- data/examples/guides/extensions/connection_blocked.rb +0 -35
- data/examples/guides/extensions/consumer_cancellation_notification.rb +0 -39
- data/examples/guides/extensions/dead_letter_exchange.rb +0 -32
- data/examples/guides/extensions/exchange_to_exchange_bindings.rb +0 -29
- data/examples/guides/extensions/per_message_ttl.rb +0 -36
- data/examples/guides/extensions/per_queue_message_ttl.rb +0 -36
- data/examples/guides/extensions/publisher_confirms.rb +0 -28
- data/examples/guides/extensions/queue_lease.rb +0 -26
- data/examples/guides/extensions/sender_selected_distribution.rb +0 -32
- data/examples/guides/getting_started/blabbr.rb +0 -27
- data/examples/guides/getting_started/hello_world.rb +0 -22
- data/examples/guides/getting_started/weathr.rb +0 -49
- data/examples/guides/queues/one_off_consumer.rb +0 -25
- data/examples/guides/queues/redeliveries.rb +0 -81
- data/profiling/basic_publish/with_4K_messages.rb +0 -33
- data/repl +0 -3
- data/spec/tls/generate-server-cert.sh +0 -8
- data/spec/tls/server-openssl.cnf +0 -10
- data/spec/tls/server.csr +0 -16
@@ -1,53 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "set"
|
6
|
-
require "thread"
|
7
|
-
require "benchmark"
|
8
|
-
|
9
|
-
require "bunny/concurrent/synchronized_sorted_set"
|
10
|
-
|
11
|
-
puts
|
12
|
-
puts "-" * 80
|
13
|
-
puts "Benchmarking on #{RUBY_DESCRIPTION}"
|
14
|
-
|
15
|
-
n = 2_000_000
|
16
|
-
s = SortedSet.new
|
17
|
-
|
18
|
-
# warm up the JIT, etc
|
19
|
-
puts "Doing a warmup run..."
|
20
|
-
n.times do |i|
|
21
|
-
s << 1
|
22
|
-
s << i
|
23
|
-
s.delete i
|
24
|
-
s << i
|
25
|
-
end
|
26
|
-
|
27
|
-
t1 = Benchmark.realtime do
|
28
|
-
n.times do |i|
|
29
|
-
s << 1
|
30
|
-
s << i
|
31
|
-
s.delete i
|
32
|
-
s << i
|
33
|
-
s.length
|
34
|
-
end
|
35
|
-
end
|
36
|
-
r1 = (n.to_f/t1.to_f)
|
37
|
-
|
38
|
-
s2 = SynchronizedSortedSet.new
|
39
|
-
t2 = Benchmark.realtime do
|
40
|
-
n.times do |i|
|
41
|
-
s2 << 1
|
42
|
-
s2 << i
|
43
|
-
s2.delete i
|
44
|
-
s2 << i
|
45
|
-
s2.length
|
46
|
-
end
|
47
|
-
end
|
48
|
-
r2 = (n.to_f/t2.to_f)
|
49
|
-
|
50
|
-
puts "Mixed sorted set ops, rate: #{(r1 / 1000).round(2)} KGHz"
|
51
|
-
puts "Mixed synchronized sorted set ops, rate: #{(r2 / 1000).round(2)} KGHz"
|
52
|
-
puts
|
53
|
-
puts "-" * 80
|
@@ -1,49 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "benchmark"
|
4
|
-
|
5
|
-
# This tests demonstrates throughput difference of
|
6
|
-
# IO#write and IO#write_nonblock. Note that the two
|
7
|
-
# may not be equivalent depending on your
|
8
|
-
|
9
|
-
r, w = IO.pipe
|
10
|
-
|
11
|
-
# buffer size
|
12
|
-
b = 65536
|
13
|
-
|
14
|
-
read_loop = Thread.new do
|
15
|
-
loop do
|
16
|
-
begin
|
17
|
-
r.read_nonblock(b)
|
18
|
-
rescue Errno::EWOULDBLOCK, Errno::EAGAIN => e
|
19
|
-
IO.select([r])
|
20
|
-
retry
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
n = 10_000
|
26
|
-
# 7 KB
|
27
|
-
s = "a" * (7 * 1024)
|
28
|
-
Benchmark.bm do |meter|
|
29
|
-
meter.report("write:") do
|
30
|
-
n.times { w.write(s.dup) }
|
31
|
-
end
|
32
|
-
meter.report("write + flush:") do
|
33
|
-
n.times { w.write(s.dup); w.flush }
|
34
|
-
end
|
35
|
-
meter.report("write_nonblock:") do
|
36
|
-
n.times do
|
37
|
-
s2 = s.dup
|
38
|
-
begin
|
39
|
-
while !s2.empty?
|
40
|
-
written = w.write_nonblock(s2)
|
41
|
-
s2.slice!(0, written)
|
42
|
-
end
|
43
|
-
rescue Errno::EWOULDBLOCK, Errno::EAGAIN
|
44
|
-
IO.select([], [w])
|
45
|
-
retry
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/bunny.gemspec
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
#!/usr/bin/env gem build
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "base64"
|
5
|
-
require File.expand_path("../lib/bunny/version", __FILE__)
|
6
|
-
|
7
|
-
Gem::Specification.new do |s|
|
8
|
-
s.name = "bunny"
|
9
|
-
s.version = Bunny::VERSION.dup
|
10
|
-
s.homepage = "http://rubybunny.info"
|
11
|
-
s.summary = "Popular easy to use Ruby client for RabbitMQ"
|
12
|
-
s.description = "Easy to use, feature complete Ruby client for RabbitMQ 3.3 and later versions."
|
13
|
-
s.license = "MIT"
|
14
|
-
s.required_ruby_version = Gem::Requirement.new(">= 2.2")
|
15
|
-
|
16
|
-
# Sorted alphabetically.
|
17
|
-
s.authors = [
|
18
|
-
"Chris Duncan",
|
19
|
-
"Eric Lindvall",
|
20
|
-
"Jakub Stastny aka botanicus",
|
21
|
-
"Michael S. Klishin",
|
22
|
-
"Stefan Kaes"]
|
23
|
-
|
24
|
-
s.email = ["michael.s.klishin@gmail.com"]
|
25
|
-
|
26
|
-
# Dependencies
|
27
|
-
s.add_runtime_dependency 'amq-protocol', '~> 2.3', '>= 2.3.1'
|
28
|
-
|
29
|
-
# Files.
|
30
|
-
s.extra_rdoc_files = ["README.md"]
|
31
|
-
s.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^bin/ci/}) }
|
32
|
-
s.test_files = `git ls-files -- spec/*`.split("\n")
|
33
|
-
s.require_paths = ["lib"]
|
34
|
-
end
|
data/docker-compose.yml
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
version: '3.7'
|
2
|
-
services:
|
3
|
-
rabbitmq:
|
4
|
-
build: ./docker
|
5
|
-
container_name: bunny_rabbitmq
|
6
|
-
environment:
|
7
|
-
RABBITMQ_NODENAME: bunny
|
8
|
-
# see CONTRIBUTING.md
|
9
|
-
BUNNY_RABBITMQ_HOSTNAME: mercurio
|
10
|
-
# link to spec specific configuration
|
11
|
-
RABBITMQ_CONFIG_FILE: /spec/config/rabbitmq.conf
|
12
|
-
RABBITMQ_ENABLED_PLUGINS_FILE: /spec/config/enabled_plugins
|
13
|
-
# send logs to stdout
|
14
|
-
RABBITMQ_LOGS: '-'
|
15
|
-
RABBITMQ_SASL_LOGS: '-'
|
16
|
-
ports:
|
17
|
-
- 5671-5672:5671-5672
|
18
|
-
- 15672:15672
|
19
|
-
volumes:
|
20
|
-
- ./spec:/spec:ro
|
21
|
-
toxiproxy:
|
22
|
-
container_name: toxiproxy
|
23
|
-
image: shopify/toxiproxy
|
24
|
-
ports:
|
25
|
-
- 8474:8474
|
26
|
-
- 11111:11111
|
27
|
-
depends_on:
|
28
|
-
- rabbitmq
|
data/docker/Dockerfile
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
FROM ubuntu:18.04
|
2
|
-
|
3
|
-
RUN apt-get update -y
|
4
|
-
RUN apt-get install -y gnupg2 wget
|
5
|
-
RUN wget -O - "https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc" | apt-key add -
|
6
|
-
|
7
|
-
COPY apt/sources.list.d/bintray.rabbitmq.list /etc/apt/sources.list.d/bintray.rabbitmq.list
|
8
|
-
COPY apt/preferences.d/erlang /etc/apt/preferences.d/erlang
|
9
|
-
|
10
|
-
RUN apt-get update -y && apt-get upgrade -y
|
11
|
-
|
12
|
-
RUN apt-get install -y erlang-base \
|
13
|
-
erlang-asn1 erlang-crypto erlang-eldap erlang-ftp erlang-inets \
|
14
|
-
erlang-mnesia erlang-os-mon erlang-parsetools erlang-public-key \
|
15
|
-
erlang-runtime-tools erlang-snmp erlang-ssl \
|
16
|
-
erlang-syntax-tools erlang-tftp erlang-tools erlang-xmerl
|
17
|
-
|
18
|
-
RUN apt-get install -y rabbitmq-server
|
19
|
-
|
20
|
-
COPY docker-entrypoint.sh /
|
21
|
-
|
22
|
-
ENTRYPOINT /docker-entrypoint.sh
|
23
|
-
|
24
|
-
EXPOSE 5671 5672 15672
|
data/docker/docker-entrypoint.sh
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
server=rabbitmq-server
|
3
|
-
ctl=rabbitmqctl
|
4
|
-
delay=5
|
5
|
-
|
6
|
-
echo 'Starting a RabbitMQ node'
|
7
|
-
$server -detached
|
8
|
-
|
9
|
-
echo "Waiting for RabbitMQ to finish startup..."
|
10
|
-
|
11
|
-
$ctl await_startup --timeout 15
|
12
|
-
|
13
|
-
$ctl add_user bunny_gem bunny_password
|
14
|
-
$ctl add_user bunny_reader reader_password
|
15
|
-
|
16
|
-
$ctl add_vhost bunny_testbed
|
17
|
-
|
18
|
-
$ctl set_permissions -p / guest '.*' '.*' '.*'
|
19
|
-
$ctl set_permissions -p bunny_testbed bunny_gem '.*' '.*' '.*'
|
20
|
-
$ctl set_permissions -p bunny_testbed guest '.*' '.*' '.*'
|
21
|
-
$ctl set_permissions -p bunny_testbed bunny_reader '^---$' '^---$' '.*'
|
22
|
-
|
23
|
-
$ctl shutdown --timeout 10
|
24
|
-
|
25
|
-
echo 'Starting a RabbitMQ node in foreground (use Ctrl-C to stop)'
|
26
|
-
exec $server
|
data/docker/rabbitmq.conf
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
listeners.tcp.1 = 0.0.0.0:5672
|
2
|
-
|
3
|
-
listeners.ssl.default = 5671
|
4
|
-
|
5
|
-
ssl_options.cacertfile = /spec/tls/ca_certificate.pem
|
6
|
-
ssl_options.certfile = /spec/tls/server_certificate.pem
|
7
|
-
ssl_options.keyfile = /spec/tls/server_key.pem
|
8
|
-
ssl_options.verify = verify_none
|
9
|
-
ssl_options.fail_if_no_peer_cert = false
|
10
|
-
|
11
|
-
ssl_options.honor_cipher_order = true
|
12
|
-
ssl_options.honor_ecc_order = true
|
13
|
-
ssl_options.client_renegotiation = false
|
14
|
-
ssl_options.secure_renegotiate = true
|
15
|
-
|
16
|
-
ssl_options.ciphers.1 = ECDHE-ECDSA-AES256-GCM-SHA384
|
17
|
-
ssl_options.ciphers.2 = ECDHE-RSA-AES256-GCM-SHA384
|
18
|
-
ssl_options.ciphers.3 = ECDH-ECDSA-AES256-GCM-SHA384
|
19
|
-
ssl_options.ciphers.4 = ECDH-RSA-AES256-GCM-SHA384
|
20
|
-
ssl_options.ciphers.5 = DHE-RSA-AES256-GCM-SHA384
|
21
|
-
ssl_options.ciphers.6 = DHE-DSS-AES256-GCM-SHA384
|
22
|
-
ssl_options.ciphers.7 = ECDHE-ECDSA-AES128-GCM-SHA256
|
23
|
-
ssl_options.ciphers.8 = ECDHE-RSA-AES128-GCM-SHA256
|
24
|
-
ssl_options.ciphers.9 = ECDH-ECDSA-AES128-GCM-SHA256
|
25
|
-
ssl_options.ciphers.10 = ECDH-RSA-AES128-GCM-SHA256
|
26
|
-
ssl_options.ciphers.11 = DHE-RSA-AES128-GCM-SHA256
|
27
|
-
ssl_options.ciphers.12 = DHE-DSS-AES128-GCM-SHA256
|
28
|
-
|
29
|
-
loopback_users = none
|
@@ -1,16 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "bundler"
|
5
|
-
Bundler.setup
|
6
|
-
|
7
|
-
$:.unshift(File.expand_path("../../../lib", __FILE__))
|
8
|
-
|
9
|
-
require 'bunny'
|
10
|
-
|
11
|
-
begin
|
12
|
-
conn = Bunny.new("amqp://guest8we78w7e8:guest2378278@127.0.0.1")
|
13
|
-
conn.start
|
14
|
-
rescue Bunny::PossibleAuthenticationFailureError => e
|
15
|
-
puts "Could not authenticate as #{conn.username}"
|
16
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "bundler"
|
5
|
-
Bundler.setup
|
6
|
-
|
7
|
-
$:.unshift(File.expand_path("../../../lib", __FILE__))
|
8
|
-
|
9
|
-
require 'bunny'
|
10
|
-
|
11
|
-
conn = Bunny.new(:heartbeat_timeout => 8)
|
12
|
-
conn.start
|
13
|
-
|
14
|
-
ch = conn.create_channel
|
15
|
-
x = ch.topic("bunny.examples.recovery.topic", :durable => false)
|
16
|
-
q = ch.queue("bunny.examples.recovery.client_named_queue2", :durable => true)
|
17
|
-
q.purge
|
18
|
-
|
19
|
-
q.bind(x, :routing_key => "abc").bind(x, :routing_key => "def")
|
20
|
-
|
21
|
-
loop do
|
22
|
-
sleep 8
|
23
|
-
body = rand.to_s
|
24
|
-
|
25
|
-
begin
|
26
|
-
x.publish(body, :routing_key => ["abc", "def"].sample)
|
27
|
-
puts "Published #{body}"
|
28
|
-
# happens when a message is published before the connection
|
29
|
-
# is recovered
|
30
|
-
rescue Exception => e
|
31
|
-
end
|
32
|
-
|
33
|
-
sleep 1.5
|
34
|
-
_, _, payload = q.pop
|
35
|
-
if payload
|
36
|
-
puts "Consumed #{payload}"
|
37
|
-
else
|
38
|
-
puts "Consumed nothing"
|
39
|
-
end
|
40
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "bundler"
|
5
|
-
Bundler.setup
|
6
|
-
|
7
|
-
$:.unshift(File.expand_path("../../../lib", __FILE__))
|
8
|
-
|
9
|
-
require 'bunny'
|
10
|
-
|
11
|
-
conn = Bunny.new(heartbeat_timeout: 8)
|
12
|
-
conn.start
|
13
|
-
|
14
|
-
ch = conn.create_channel
|
15
|
-
x = ch.topic("bunny.examples.recovery.topic", :durable => false)
|
16
|
-
q = ch.queue("bunny.examples.recovery.client_named_queue1", :durable => false)
|
17
|
-
|
18
|
-
q.bind(x, :routing_key => "abc").bind(x, :routing_key => "def")
|
19
|
-
|
20
|
-
q.subscribe do |delivery_info, metadata, payload|
|
21
|
-
puts "Consumed #{payload}"
|
22
|
-
end
|
23
|
-
|
24
|
-
loop do
|
25
|
-
sleep 2
|
26
|
-
data = rand.to_s
|
27
|
-
rk = ["abc", "def"].sample
|
28
|
-
|
29
|
-
begin
|
30
|
-
x.publish(data, :routing_key => rk)
|
31
|
-
puts "Published #{data}, routing key: #{rk}"
|
32
|
-
# happens when a message is published before the connection
|
33
|
-
# is recovered
|
34
|
-
rescue Exception => e
|
35
|
-
end
|
36
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "bundler"
|
5
|
-
Bundler.setup
|
6
|
-
|
7
|
-
$:.unshift(File.expand_path("../../../lib", __FILE__))
|
8
|
-
|
9
|
-
require 'bunny'
|
10
|
-
|
11
|
-
conn = Bunny.new(heartbeat_timeout: 8)
|
12
|
-
conn.start
|
13
|
-
|
14
|
-
ch1 = conn.create_channel
|
15
|
-
x1 = ch1.topic("bunny.examples.recovery.e1", :durable => false)
|
16
|
-
q1 = ch1.queue("bunny.examples.recovery.q1", :durable => false)
|
17
|
-
|
18
|
-
q1.bind(x1, :routing_key => "abc").bind(x1, :routing_key => "def")
|
19
|
-
|
20
|
-
ch2 = conn.create_channel
|
21
|
-
x2 = ch2.topic("bunny.examples.recovery.e2", :durable => false)
|
22
|
-
q2 = ch2.queue("bunny.examples.recovery.q2", :durable => false)
|
23
|
-
|
24
|
-
q2.bind(x2, :routing_key => "abc").bind(x2, :routing_key => "def")
|
25
|
-
|
26
|
-
q1.subscribe do |delivery_info, metadata, payload|
|
27
|
-
puts "Consumed #{payload} at stage one"
|
28
|
-
x2.publish(payload, :routing_key => ["abc", "def", "xyz"].sample)
|
29
|
-
end
|
30
|
-
|
31
|
-
q2.subscribe do |delivery_info, metadata, payload|
|
32
|
-
puts "Consumed #{payload} at stage two"
|
33
|
-
end
|
34
|
-
|
35
|
-
loop do
|
36
|
-
sleep 2
|
37
|
-
rk = ["abc", "def", "ghi", "xyz"].sample
|
38
|
-
puts "Publishing with routing key #{rk}"
|
39
|
-
|
40
|
-
begin
|
41
|
-
x1.publish(rand.to_s, :routing_key => rk)
|
42
|
-
# happens when a message is published before the connection
|
43
|
-
# is recovered
|
44
|
-
rescue Bunny::ConnectionClosedError => e
|
45
|
-
end
|
46
|
-
end
|
@@ -1,109 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "bundler"
|
5
|
-
Bundler.setup
|
6
|
-
|
7
|
-
$:.unshift(File.expand_path("../../../lib", __FILE__))
|
8
|
-
|
9
|
-
require 'Bunny'
|
10
|
-
|
11
|
-
conn = Bunny.new(:heartbeat_timeout => 8)
|
12
|
-
conn.start
|
13
|
-
|
14
|
-
ch0 = conn.create_channel
|
15
|
-
ch1 = conn.create_channel
|
16
|
-
ch2 = conn.create_channel
|
17
|
-
ch3 = conn.create_channel
|
18
|
-
|
19
|
-
x = ch1.topic("hb.examples.recovery.topic", :durable => false)
|
20
|
-
q1 = ch1.queue("hb.examples.recovery.client_named_queue1", :durable => false)
|
21
|
-
q2 = ch2.queue("hb.examples.recovery.client_named_queue2", :durable => false)
|
22
|
-
q3 = ch3.queue("hb.examples.recovery.client_named_queue3", :durable => false)
|
23
|
-
|
24
|
-
q1.bind(x, :routing_key => "abc")
|
25
|
-
q2.bind(x, :routing_key => "def")
|
26
|
-
q3.bind(x, :routing_key => "xyz")
|
27
|
-
|
28
|
-
x0 = ch0.fanout("hb.examples.recovery.fanout0")
|
29
|
-
x1 = ch1.fanout("hb.examples.recovery.fanout1")
|
30
|
-
x2 = ch2.fanout("hb.examples.recovery.fanout2")
|
31
|
-
x3 = ch3.fanout("hb.examples.recovery.fanout3")
|
32
|
-
|
33
|
-
q4 = ch1.queue("", :exclusive => true)
|
34
|
-
q4.bind(x0)
|
35
|
-
|
36
|
-
q5 = ch2.queue("", :exclusive => true)
|
37
|
-
q5.bind(x1)
|
38
|
-
|
39
|
-
q6 = ch3.queue("", :exclusive => true)
|
40
|
-
q6.bind(x2)
|
41
|
-
q6.bind(x3)
|
42
|
-
|
43
|
-
|
44
|
-
q1.subscribe do |delivery_info, metadata, payload|
|
45
|
-
puts "[Q1] Consumed #{payload} on channel #{q1.channel.id}"
|
46
|
-
if ch0.open?
|
47
|
-
puts "Publishing a reply on channel #{ch0.id} which is open"
|
48
|
-
x0.publish(Time.now.to_i.to_s)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
q2.subscribe do |delivery_info, metadata, payload|
|
53
|
-
puts "[Q2] Consumed #{payload} on channel #{q2.channel.id}"
|
54
|
-
|
55
|
-
if ch1.open?
|
56
|
-
puts "Publishing a reply on channel #{ch1.id} which is open"
|
57
|
-
x1.publish(Time.now.to_i.to_s)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
q3.subscribe do |delivery_info, metadata, payload|
|
62
|
-
puts "[Q3] Consumed #{payload} (consumer 1, channel #{q3.channel.id})"
|
63
|
-
|
64
|
-
if ch2.open?
|
65
|
-
puts "Publishing a reply on channel #{ch1.id} which is open"
|
66
|
-
x2.publish(Time.now.to_i.to_s)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
q3.subscribe do |delivery_info, metadata, payload|
|
71
|
-
puts "[Q3] Consumed #{payload} (consumer 2, channel #{q3.channel.id})"
|
72
|
-
|
73
|
-
if ch3.open?
|
74
|
-
puts "Publishing a reply on channel #{ch3.id} which is open"
|
75
|
-
x3.publish(Time.now.to_i.to_s)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
q4.subscribe do |delivery_info, metadata, payload|
|
80
|
-
puts "[Q4] Consumed #{payload} on channel #{q4.channel.id}"
|
81
|
-
end
|
82
|
-
|
83
|
-
q5.subscribe do |delivery_info, metadata, payload|
|
84
|
-
puts "[Q5] Consumed #{payload} on channel #{q5.channel.id}"
|
85
|
-
end
|
86
|
-
|
87
|
-
q6.subscribe do |delivery_info, metadata, payload|
|
88
|
-
puts "[Q6] Consumed #{payload} on channel #{q6.channel.id}"
|
89
|
-
end
|
90
|
-
|
91
|
-
loop do
|
92
|
-
sleep 1
|
93
|
-
data = rand.to_s
|
94
|
-
rk = ["abc", "def", "xyz", Time.now.to_i.to_s].sample
|
95
|
-
|
96
|
-
begin
|
97
|
-
3.times do
|
98
|
-
x.publish(rand.to_s, :routing_key => rk)
|
99
|
-
puts "Published #{data}, routing key: #{rk} on channel #{x.channel.id}"
|
100
|
-
end
|
101
|
-
# happens when a message is published before the connection
|
102
|
-
# is recovered
|
103
|
-
rescue Exception => e
|
104
|
-
puts "Exception: #{e.message}"
|
105
|
-
# e.backtrace.each do |line|
|
106
|
-
# puts "\t#{line}"
|
107
|
-
# end
|
108
|
-
end
|
109
|
-
end
|