bunny 2.7.4 → 2.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +61 -35
- data/lib/bunny/channel.rb +186 -50
- data/lib/bunny/channel_id_allocator.rb +3 -1
- data/lib/bunny/consumer.rb +2 -2
- data/lib/bunny/consumer_work_pool.rb +2 -1
- data/lib/bunny/cruby/socket.rb +3 -0
- data/lib/bunny/cruby/ssl_socket.rb +6 -1
- data/lib/bunny/delivery_info.rb +1 -1
- data/lib/bunny/heartbeat_sender.rb +2 -1
- data/lib/bunny/jruby/ssl_socket.rb +5 -0
- data/lib/bunny/queue.rb +36 -8
- data/lib/bunny/reader_loop.rb +22 -10
- data/lib/bunny/session.rb +152 -65
- data/lib/bunny/test_kit.rb +14 -0
- data/lib/bunny/transport.rb +132 -49
- data/lib/bunny/version.rb +1 -1
- data/lib/bunny.rb +45 -4
- metadata +37 -225
- data/.github/ISSUE_TEMPLATE.md +0 -18
- data/.gitignore +0 -28
- data/.rspec +0 -1
- data/.travis.yml +0 -20
- data/.yardopts +0 -8
- data/CONTRIBUTING.md +0 -111
- data/ChangeLog.md +0 -1831
- data/Gemfile +0 -53
- data/LICENSE +0 -21
- data/Rakefile +0 -46
- 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/bin/ci/before_build +0 -46
- data/bunny.gemspec +0 -35
- data/docker/Dockerfile +0 -16
- data/docker/docker-entrypoint.sh +0 -37
- data/docker-compose.yml +0 -18
- 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/config/enabled_plugins +0 -1
- data/spec/config/rabbitmq.config +0 -19
- data/spec/higher_level_api/integration/basic_ack_spec.rb +0 -230
- data/spec/higher_level_api/integration/basic_cancel_spec.rb +0 -142
- data/spec/higher_level_api/integration/basic_consume_spec.rb +0 -349
- data/spec/higher_level_api/integration/basic_consume_with_objects_spec.rb +0 -54
- data/spec/higher_level_api/integration/basic_get_spec.rb +0 -80
- data/spec/higher_level_api/integration/basic_nack_spec.rb +0 -82
- data/spec/higher_level_api/integration/basic_publish_spec.rb +0 -74
- data/spec/higher_level_api/integration/basic_qos_spec.rb +0 -57
- data/spec/higher_level_api/integration/basic_reject_spec.rb +0 -152
- data/spec/higher_level_api/integration/basic_return_spec.rb +0 -33
- data/spec/higher_level_api/integration/channel_close_spec.rb +0 -25
- data/spec/higher_level_api/integration/channel_open_spec.rb +0 -57
- data/spec/higher_level_api/integration/connection_recovery_spec.rb +0 -471
- data/spec/higher_level_api/integration/connection_spec.rb +0 -559
- data/spec/higher_level_api/integration/connection_stop_spec.rb +0 -83
- data/spec/higher_level_api/integration/consumer_cancellation_notification_spec.rb +0 -128
- data/spec/higher_level_api/integration/dead_lettering_spec.rb +0 -75
- data/spec/higher_level_api/integration/exchange_bind_spec.rb +0 -31
- data/spec/higher_level_api/integration/exchange_declare_spec.rb +0 -237
- data/spec/higher_level_api/integration/exchange_delete_spec.rb +0 -105
- data/spec/higher_level_api/integration/exchange_unbind_spec.rb +0 -40
- data/spec/higher_level_api/integration/exclusive_queue_spec.rb +0 -28
- data/spec/higher_level_api/integration/heartbeat_spec.rb +0 -49
- data/spec/higher_level_api/integration/merry_go_round_spec.rb +0 -85
- data/spec/higher_level_api/integration/message_properties_access_spec.rb +0 -95
- data/spec/higher_level_api/integration/predeclared_exchanges_spec.rb +0 -24
- data/spec/higher_level_api/integration/publisher_confirms_spec.rb +0 -191
- data/spec/higher_level_api/integration/publishing_edge_cases_spec.rb +0 -87
- data/spec/higher_level_api/integration/queue_bind_spec.rb +0 -109
- data/spec/higher_level_api/integration/queue_declare_spec.rb +0 -221
- data/spec/higher_level_api/integration/queue_delete_spec.rb +0 -41
- data/spec/higher_level_api/integration/queue_purge_spec.rb +0 -30
- data/spec/higher_level_api/integration/queue_unbind_spec.rb +0 -54
- data/spec/higher_level_api/integration/read_only_consumer_spec.rb +0 -60
- data/spec/higher_level_api/integration/sender_selected_distribution_spec.rb +0 -36
- data/spec/higher_level_api/integration/tls_connection_spec.rb +0 -222
- data/spec/higher_level_api/integration/tx_commit_spec.rb +0 -21
- data/spec/higher_level_api/integration/tx_rollback_spec.rb +0 -21
- data/spec/higher_level_api/integration/with_channel_spec.rb +0 -25
- data/spec/issues/issue100_spec.rb +0 -42
- data/spec/issues/issue141_spec.rb +0 -43
- data/spec/issues/issue202_spec.rb +0 -15
- data/spec/issues/issue224_spec.rb +0 -40
- data/spec/issues/issue465_spec.rb +0 -32
- data/spec/issues/issue78_spec.rb +0 -72
- data/spec/issues/issue83_spec.rb +0 -30
- data/spec/issues/issue97_attachment.json +0 -1
- data/spec/issues/issue97_spec.rb +0 -175
- data/spec/lower_level_api/integration/basic_cancel_spec.rb +0 -83
- data/spec/lower_level_api/integration/basic_consume_spec.rb +0 -99
- data/spec/spec_helper.rb +0 -51
- data/spec/stress/channel_close_stress_spec.rb +0 -64
- data/spec/stress/channel_open_stress_spec.rb +0 -84
- data/spec/stress/channel_open_stress_with_single_threaded_connection_spec.rb +0 -28
- data/spec/stress/concurrent_consumers_stress_spec.rb +0 -71
- data/spec/stress/concurrent_publishers_stress_spec.rb +0 -54
- data/spec/stress/connection_open_close_spec.rb +0 -52
- data/spec/stress/long_running_consumer_spec.rb +0 -84
- data/spec/tls/ca_certificate.pem +0 -29
- data/spec/tls/ca_key.pem +0 -52
- data/spec/tls/client_certificate.pem +0 -29
- data/spec/tls/client_key.pem +0 -51
- data/spec/tls/generate-server-cert.sh +0 -8
- data/spec/tls/server-openssl.cnf +0 -10
- data/spec/tls/server.csr +0 -16
- data/spec/tls/server_certificate.pem +0 -29
- data/spec/tls/server_key.pem +0 -51
- data/spec/unit/bunny_spec.rb +0 -15
- data/spec/unit/concurrent/atomic_fixnum_spec.rb +0 -35
- data/spec/unit/concurrent/condition_spec.rb +0 -82
- data/spec/unit/concurrent/linked_continuation_queue_spec.rb +0 -35
- data/spec/unit/concurrent/synchronized_sorted_set_spec.rb +0 -73
- data/spec/unit/exchange_recovery_spec.rb +0 -39
- data/spec/unit/version_delivery_tag_spec.rb +0 -28
@@ -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_interval => 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_interval => 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_interval => 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_interval => 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
|
@@ -1,35 +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_interval => 8)
|
12
|
-
conn.start
|
13
|
-
|
14
|
-
ch = conn.create_channel
|
15
|
-
x = ch.topic("bunny.examples.recovery.topic", :durable => false)
|
16
|
-
q = ch.queue("", :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(rand.to_s, :routing_key => rk)
|
31
|
-
# happens when a message is published before the connection
|
32
|
-
# is recovered
|
33
|
-
rescue Bunny::ConnectionClosedError => e
|
34
|
-
end
|
35
|
-
end
|
@@ -1,27 +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_interval => 8)
|
12
|
-
conn.start
|
13
|
-
|
14
|
-
begin
|
15
|
-
ch2 = conn.create_channel
|
16
|
-
q = "bunny.examples.recovery.q#{rand}"
|
17
|
-
|
18
|
-
ch2.queue_declare(q, :durable => false)
|
19
|
-
ch2.queue_declare(q, :durable => true)
|
20
|
-
rescue Bunny::PreconditionFailed => e
|
21
|
-
puts "Channel-level exception! Code: #{e.channel_close.reply_code}, message: #{e.channel_close.reply_text}"
|
22
|
-
ensure
|
23
|
-
conn.create_channel.queue_delete(q)
|
24
|
-
end
|
25
|
-
|
26
|
-
puts "Disconnecting..."
|
27
|
-
conn.close
|
@@ -1,34 +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_interval => 8, :automatically_recover => false)
|
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 1.5
|
23
|
-
body = rand.to_s
|
24
|
-
puts "Published #{body}"
|
25
|
-
x.publish(body, :routing_key => ["abc", "def"].sample)
|
26
|
-
|
27
|
-
sleep 1.5
|
28
|
-
_, _, payload = q.pop
|
29
|
-
if payload
|
30
|
-
puts "Consumed #{payload}"
|
31
|
-
else
|
32
|
-
puts "Consumed nothing"
|
33
|
-
end
|
34
|
-
end
|
@@ -1,17 +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
|
-
|
12
|
-
conn = Bunny.new(:heartbeat_interval => 2)
|
13
|
-
conn.start
|
14
|
-
|
15
|
-
c = conn.create_channel
|
16
|
-
|
17
|
-
sleep 10
|
@@ -1,23 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'bunny'
|
3
|
-
|
4
|
-
Bundler.setup
|
5
|
-
|
6
|
-
begin
|
7
|
-
connection = Bunny.new(:automatically_recover => false)
|
8
|
-
connection.start
|
9
|
-
|
10
|
-
ch = connection.channel
|
11
|
-
q = ch.queue("manually_reconnecting_consumer", :exclusive => true)
|
12
|
-
|
13
|
-
q.subscribe(:block => true) do |_, _, payload|
|
14
|
-
puts "Consumed #{payload}"
|
15
|
-
end
|
16
|
-
rescue Bunny::NetworkFailure => e
|
17
|
-
ch.maybe_kill_consumer_work_pool!
|
18
|
-
|
19
|
-
sleep 10
|
20
|
-
puts "Recovering manually..."
|
21
|
-
|
22
|
-
retry
|
23
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'bunny'
|
3
|
-
|
4
|
-
Bundler.setup
|
5
|
-
|
6
|
-
begin
|
7
|
-
connection = Bunny.new(:automatically_recover => false)
|
8
|
-
connection.start
|
9
|
-
|
10
|
-
ch = connection.channel
|
11
|
-
x = ch.default_exchange
|
12
|
-
|
13
|
-
loop do
|
14
|
-
10.times do |i|
|
15
|
-
print "."
|
16
|
-
x.publish("")
|
17
|
-
end
|
18
|
-
|
19
|
-
sleep 3.0
|
20
|
-
end
|
21
|
-
rescue Bunny::NetworkFailure => e
|
22
|
-
ch.maybe_kill_consumer_work_pool!
|
23
|
-
|
24
|
-
sleep 10
|
25
|
-
puts "Recovering manually..."
|
26
|
-
|
27
|
-
retry
|
28
|
-
end
|
@@ -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://guest:guest@aksjhdkajshdkj.example82737.com")
|
13
|
-
conn.start
|
14
|
-
rescue Bunny::TCPConnectionFailed => e
|
15
|
-
puts "Connection to #{conn.hostname} failed"
|
16
|
-
end
|
@@ -1,50 +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
|
-
HIGH_PRIORITY_Q = "bunny.examples.priority.hilo.high"
|
12
|
-
LOW_PRIORITY_Q = "bunny.examples.priority.hilo.low"
|
13
|
-
|
14
|
-
conn = Bunny.new(:heartbeat_interval => 8)
|
15
|
-
conn.start
|
16
|
-
|
17
|
-
ch1 = conn.create_channel
|
18
|
-
ch2 = conn.create_channel
|
19
|
-
hi_q = ch1.queue(HIGH_PRIORITY_Q, :durable => false)
|
20
|
-
lo_q = ch2.queue(LOW_PRIORITY_Q, :durable => false)
|
21
|
-
|
22
|
-
ch3 = conn.create_channel
|
23
|
-
x = ch3.default_exchange
|
24
|
-
|
25
|
-
# create a backlog of low priority messages
|
26
|
-
30.times do
|
27
|
-
x.publish(rand.to_s, :routing_key => LOW_PRIORITY_Q)
|
28
|
-
end
|
29
|
-
|
30
|
-
# and a much smaller one of high priority messages
|
31
|
-
3.times do
|
32
|
-
x.publish(rand.to_s, :routing_key => HIGH_PRIORITY_Q)
|
33
|
-
end
|
34
|
-
|
35
|
-
hi_q.subscribe do |delivery_info, metadata, payload|
|
36
|
-
puts "[high] Consumed #{payload}"
|
37
|
-
end
|
38
|
-
|
39
|
-
lo_q.subscribe do |delivery_info, metadata, payload|
|
40
|
-
puts "[low] Consumed #{payload}"
|
41
|
-
end
|
42
|
-
|
43
|
-
loop do
|
44
|
-
sleep 0.5
|
45
|
-
data = rand.to_s
|
46
|
-
rk = [HIGH_PRIORITY_Q, LOW_PRIORITY_Q].sample
|
47
|
-
|
48
|
-
x.publish(data, :routing_key => rk)
|
49
|
-
puts "Published #{data}, routing key: #{rk}"
|
50
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "bunny"
|
6
|
-
|
7
|
-
puts "=> Direct exchange routing"
|
8
|
-
puts
|
9
|
-
|
10
|
-
conn = Bunny.new
|
11
|
-
conn.start
|
12
|
-
|
13
|
-
ch = conn.create_channel
|
14
|
-
x = ch.direct("examples.imaging")
|
15
|
-
|
16
|
-
q1 = ch.queue("", :auto_delete => true).bind(x, :routing_key => "resize")
|
17
|
-
q1.subscribe do |delivery_info, properties, payload|
|
18
|
-
puts "[consumer] #{q1.name} received a 'resize' message"
|
19
|
-
end
|
20
|
-
q2 = ch.queue("", :auto_delete => true).bind(x, :routing_key => "watermark")
|
21
|
-
q2.subscribe do |delivery_info, properties, payload|
|
22
|
-
puts "[consumer] #{q2.name} received a 'watermark' message"
|
23
|
-
end
|
24
|
-
|
25
|
-
# just an example
|
26
|
-
data = rand.to_s
|
27
|
-
x.publish(data, :routing_key => "resize")
|
28
|
-
x.publish(data, :routing_key => "watermark")
|
29
|
-
|
30
|
-
sleep 0.5
|
31
|
-
x.delete
|
32
|
-
q1.delete
|
33
|
-
q2.delete
|
34
|
-
|
35
|
-
puts "Disconnecting..."
|
36
|
-
conn.close
|
@@ -1,28 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "bunny"
|
6
|
-
|
7
|
-
puts "=> Fanout exchange routing"
|
8
|
-
puts
|
9
|
-
|
10
|
-
conn = Bunny.new
|
11
|
-
conn.start
|
12
|
-
|
13
|
-
ch = conn.create_channel
|
14
|
-
x = ch.fanout("examples.pings")
|
15
|
-
|
16
|
-
10.times do |i|
|
17
|
-
q = ch.queue("", :auto_delete => true).bind(x)
|
18
|
-
q.subscribe do |delivery_info, properties, payload|
|
19
|
-
puts "[consumer] #{q.name} received a message: #{payload}"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
x.publish("Ping")
|
24
|
-
|
25
|
-
sleep 0.5
|
26
|
-
x.delete
|
27
|
-
puts "Disconnecting..."
|
28
|
-
conn.close
|
@@ -1,31 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "bunny"
|
6
|
-
|
7
|
-
puts "=> Headers exchange routing"
|
8
|
-
puts
|
9
|
-
|
10
|
-
conn = Bunny.new
|
11
|
-
conn.start
|
12
|
-
|
13
|
-
ch = conn.create_channel
|
14
|
-
x = ch.headers("headers")
|
15
|
-
|
16
|
-
q1 = ch.queue("", :exclusive => true).bind(x, :arguments => {"os" => "linux", "cores" => 8, "x-match" => "all"})
|
17
|
-
q2 = ch.queue("", :exclusive => true).bind(x, :arguments => {"os" => "osx", "cores" => 4, "x-match" => "any"})
|
18
|
-
|
19
|
-
q1.subscribe do |delivery_info, properties, content|
|
20
|
-
puts "#{q1.name} received #{content}"
|
21
|
-
end
|
22
|
-
q2.subscribe do |delivery_info, properties, content|
|
23
|
-
puts "#{q2.name} received #{content}"
|
24
|
-
end
|
25
|
-
|
26
|
-
x.publish("8 cores/Linux", :headers => {"os" => "linux", "cores" => 8})
|
27
|
-
x.publish("8 cores/OS X", :headers => {"os" => "osx", "cores" => 8})
|
28
|
-
x.publish("4 cores/Linux", :headers => {"os" => "linux", "cores" => 4})
|
29
|
-
|
30
|
-
sleep 0.5
|
31
|
-
conn.close
|
@@ -1,30 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "bunny"
|
6
|
-
|
7
|
-
puts "=> Publishing messages as mandatory"
|
8
|
-
puts
|
9
|
-
|
10
|
-
conn = Bunny.new
|
11
|
-
conn.start
|
12
|
-
|
13
|
-
ch = conn.create_channel
|
14
|
-
x = ch.default_exchange
|
15
|
-
|
16
|
-
x.on_return do |return_info, properties, content|
|
17
|
-
puts "Got a returned message: #{content}"
|
18
|
-
end
|
19
|
-
|
20
|
-
q = ch.queue("", :exclusive => true)
|
21
|
-
q.subscribe do |delivery_info, properties, content|
|
22
|
-
puts "Consumed a message: #{content}"
|
23
|
-
end
|
24
|
-
|
25
|
-
x.publish("This will NOT be returned", :mandatory => true, :routing_key => q.name)
|
26
|
-
x.publish("This will be returned", :mandatory => true, :routing_key => "akjhdfkjsh#{rand}")
|
27
|
-
|
28
|
-
sleep 0.5
|
29
|
-
puts "Disconnecting..."
|
30
|
-
conn.close
|
@@ -1,30 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "bunny"
|
6
|
-
|
7
|
-
STDOUT.sync = true
|
8
|
-
|
9
|
-
puts "=> Demonstrating alternate exchanges"
|
10
|
-
puts
|
11
|
-
|
12
|
-
conn = Bunny.new
|
13
|
-
conn.start
|
14
|
-
|
15
|
-
ch = conn.create_channel
|
16
|
-
x1 = ch.fanout("bunny.examples.ae.exchange1", :auto_delete => true, :durable => false)
|
17
|
-
x2 = ch.fanout("bunny.examples.ae.exchange2", :auto_delete => true, :durable => false, :arguments => {
|
18
|
-
"alternate-exchange" => x1.name
|
19
|
-
})
|
20
|
-
q = ch.queue("", :exclusive => true)
|
21
|
-
q.bind(x1)
|
22
|
-
|
23
|
-
x2.publish("")
|
24
|
-
|
25
|
-
sleep 0.2
|
26
|
-
puts "Queue #{q.name} now has #{q.message_count} message in it"
|
27
|
-
|
28
|
-
sleep 0.7
|
29
|
-
puts "Disconnecting..."
|
30
|
-
conn.close
|
@@ -1,33 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "bunny"
|
6
|
-
|
7
|
-
puts "=> Demonstrating basic.nack"
|
8
|
-
puts
|
9
|
-
|
10
|
-
conn = Bunny.new
|
11
|
-
conn.start
|
12
|
-
|
13
|
-
ch = conn.create_channel
|
14
|
-
q = ch.queue("", :exclusive => true)
|
15
|
-
|
16
|
-
20.times do
|
17
|
-
q.publish("")
|
18
|
-
end
|
19
|
-
|
20
|
-
20.times do
|
21
|
-
delivery_info, _, _ = q.pop(:manual_ack => true)
|
22
|
-
|
23
|
-
if delivery_info.delivery_tag == 20
|
24
|
-
# requeue them all at once with basic.nack
|
25
|
-
ch.nack(delivery_info.delivery_tag, true, true)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
puts "Queue #{q.name} still has #{q.message_count} messages in it"
|
30
|
-
|
31
|
-
sleep 0.7
|
32
|
-
puts "Disconnecting..."
|
33
|
-
conn.close
|