bunny 2.14.4 → 2.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +30 -12
- data/lib/bunny/channel.rb +2 -2
- data/lib/bunny/queue.rb +0 -3
- data/lib/bunny/reader_loop.rb +11 -11
- data/lib/bunny/session.rb +42 -9
- data/lib/bunny/transport.rb +12 -11
- data/lib/bunny/version.rb +1 -1
- data/spec/higher_level_api/integration/basic_cancel_spec.rb +4 -4
- data/spec/higher_level_api/integration/basic_consume_spec.rb +17 -9
- data/spec/higher_level_api/integration/connection_spec.rb +26 -0
- data/spec/higher_level_api/integration/tls_connection_spec.rb +194 -189
- data/spec/issues/issue202_spec.rb +1 -1
- data/spec/issues/issue609_spec.rb +84 -0
- data/spec/issues/issue78_spec.rb +2 -2
- data/spec/lower_level_api/integration/basic_cancel_spec.rb +1 -1
- data/spec/lower_level_api/integration/basic_consume_spec.rb +8 -8
- data/spec/unit/exchange_recovery_spec.rb +2 -2
- metadata +37 -95
- data/.github/ISSUE_TEMPLATE.md +0 -18
- data/.gitignore +0 -28
- data/.rspec +0 -1
- data/.travis.yml +0 -32
- data/.yardopts +0 -8
- data/CONTRIBUTING.md +0 -132
- data/ChangeLog.md +0 -2103
- 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,39 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "bunny"
|
6
|
-
|
7
|
-
puts "=> Demonstrating consumer cancellation notification"
|
8
|
-
puts
|
9
|
-
|
10
|
-
conn = Bunny.new
|
11
|
-
conn.start
|
12
|
-
|
13
|
-
ch = conn.create_channel
|
14
|
-
|
15
|
-
module Bunny
|
16
|
-
module Examples
|
17
|
-
class ExampleConsumer < Bunny::Consumer
|
18
|
-
def cancelled?
|
19
|
-
@cancelled
|
20
|
-
end
|
21
|
-
|
22
|
-
def handle_cancellation(basic_cancel)
|
23
|
-
puts "#{@consumer_tag} was cancelled"
|
24
|
-
@cancelled = true
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
q = ch.queue("", :exclusive => true)
|
31
|
-
c = Bunny::Examples::ExampleConsumer.new(ch, q)
|
32
|
-
q.subscribe_with(c)
|
33
|
-
|
34
|
-
sleep 0.1
|
35
|
-
q.delete
|
36
|
-
|
37
|
-
sleep 0.1
|
38
|
-
puts "Disconnecting..."
|
39
|
-
conn.close
|
@@ -1,32 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "bunny"
|
6
|
-
|
7
|
-
puts "=> Demonstrating dead letter exchange"
|
8
|
-
puts
|
9
|
-
|
10
|
-
conn = Bunny.new
|
11
|
-
conn.start
|
12
|
-
|
13
|
-
ch = conn.create_channel
|
14
|
-
x = ch.fanout("amq.fanout")
|
15
|
-
dlx = ch.fanout("bunny.examples.dlx.exchange")
|
16
|
-
q = ch.queue("", :exclusive => true, :arguments => {"x-dead-letter-exchange" => dlx.name}).bind(x)
|
17
|
-
# dead letter queue
|
18
|
-
dlq = ch.queue("", :exclusive => true).bind(dlx)
|
19
|
-
|
20
|
-
x.publish("")
|
21
|
-
sleep 0.2
|
22
|
-
|
23
|
-
delivery_info, _, _ = q.pop(:manual_ack => true)
|
24
|
-
puts "#{dlq.message_count} messages dead lettered so far"
|
25
|
-
puts "Rejecting a message"
|
26
|
-
ch.nack(delivery_info.delivery_tag)
|
27
|
-
sleep 0.2
|
28
|
-
puts "#{dlq.message_count} messages dead lettered so far"
|
29
|
-
|
30
|
-
dlx.delete
|
31
|
-
puts "Disconnecting..."
|
32
|
-
conn.close
|
@@ -1,29 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "bunny"
|
6
|
-
|
7
|
-
puts "=> Demonstrating exchange-to-exchange bindings"
|
8
|
-
puts
|
9
|
-
|
10
|
-
conn = Bunny.new
|
11
|
-
conn.start
|
12
|
-
|
13
|
-
ch = conn.create_channel
|
14
|
-
x1 = ch.fanout("bunny.examples.e2e.exchange1", :auto_delete => true, :durable => false)
|
15
|
-
x2 = ch.fanout("bunny.examples.e2e.exchange2", :auto_delete => true, :durable => false)
|
16
|
-
# x1 will be the source
|
17
|
-
x2.bind(x1)
|
18
|
-
|
19
|
-
q = ch.queue("", :exclusive => true)
|
20
|
-
q.bind(x2)
|
21
|
-
|
22
|
-
x1.publish("")
|
23
|
-
|
24
|
-
sleep 0.2
|
25
|
-
puts "Queue #{q.name} now has #{q.message_count} message in it"
|
26
|
-
|
27
|
-
sleep 0.7
|
28
|
-
puts "Disconnecting..."
|
29
|
-
conn.close
|
@@ -1,36 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "bunny"
|
6
|
-
|
7
|
-
puts "=> Demonstrating per-message TTL"
|
8
|
-
puts
|
9
|
-
|
10
|
-
conn = Bunny.new
|
11
|
-
conn.start
|
12
|
-
|
13
|
-
ch = conn.create_channel
|
14
|
-
x = ch.fanout("amq.fanout")
|
15
|
-
q = ch.queue("", :exclusive => true).bind(x)
|
16
|
-
|
17
|
-
10.times do |i|
|
18
|
-
x.publish("Message #{i}", :expiration => 1000)
|
19
|
-
end
|
20
|
-
|
21
|
-
sleep 0.7
|
22
|
-
_, _, content1 = q.pop
|
23
|
-
puts "Fetched #{content1.inspect} after 0.7 second"
|
24
|
-
|
25
|
-
sleep 0.8
|
26
|
-
_, _, content2 = q.pop
|
27
|
-
msg = if content2
|
28
|
-
content2.inspect
|
29
|
-
else
|
30
|
-
"nothing"
|
31
|
-
end
|
32
|
-
puts "Fetched #{msg} after 1.5 second"
|
33
|
-
|
34
|
-
sleep 0.7
|
35
|
-
puts "Closing..."
|
36
|
-
conn.close
|
@@ -1,36 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "bunny"
|
6
|
-
|
7
|
-
puts "=> Demonstrating per-queue message TTL"
|
8
|
-
puts
|
9
|
-
|
10
|
-
conn = Bunny.new
|
11
|
-
conn.start
|
12
|
-
|
13
|
-
ch = conn.create_channel
|
14
|
-
x = ch.fanout("amq.fanout")
|
15
|
-
q = ch.queue("", :exclusive => true, :arguments => {"x-message-ttl" => 1000}).bind(x)
|
16
|
-
|
17
|
-
10.times do |i|
|
18
|
-
x.publish("Message #{i}")
|
19
|
-
end
|
20
|
-
|
21
|
-
sleep 0.7
|
22
|
-
_, _, content1 = q.pop
|
23
|
-
puts "Fetched #{content1.inspect} after 0.7 second"
|
24
|
-
|
25
|
-
sleep 0.8
|
26
|
-
_, _, content2 = q.pop
|
27
|
-
msg = if content2
|
28
|
-
content2.inspect
|
29
|
-
else
|
30
|
-
"nothing"
|
31
|
-
end
|
32
|
-
puts "Fetched #{msg} after 1.5 second"
|
33
|
-
|
34
|
-
sleep 0.7
|
35
|
-
puts "Closing..."
|
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 "=> Demonstrating publisher confirms"
|
8
|
-
puts
|
9
|
-
|
10
|
-
conn = Bunny.new
|
11
|
-
conn.start
|
12
|
-
|
13
|
-
ch = conn.create_channel
|
14
|
-
x = ch.fanout("amq.fanout")
|
15
|
-
q = ch.queue("", :exclusive => true).bind(x)
|
16
|
-
|
17
|
-
ch.confirm_select
|
18
|
-
1000.times do
|
19
|
-
x.publish("")
|
20
|
-
end
|
21
|
-
ch.wait_for_confirms # blocks calling thread until all acks are received
|
22
|
-
|
23
|
-
sleep 0.2
|
24
|
-
puts "Received acks for all published messages. #{q.name} now has #{q.message_count} messages."
|
25
|
-
|
26
|
-
sleep 0.7
|
27
|
-
puts "Disconnecting..."
|
28
|
-
conn.close
|
@@ -1,26 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "bunny"
|
6
|
-
|
7
|
-
puts "=> Demonstrating queue TTL (queue leases)"
|
8
|
-
puts
|
9
|
-
|
10
|
-
conn = Bunny.new
|
11
|
-
conn.start
|
12
|
-
|
13
|
-
ch = conn.create_channel
|
14
|
-
q = ch.queue("", :exclusive => true, :arguments => {"x-expires" => 300})
|
15
|
-
|
16
|
-
sleep 0.4
|
17
|
-
begin
|
18
|
-
# this will raise because the queue is already deleted
|
19
|
-
q.message_count
|
20
|
-
rescue Bunny::NotFound => nfe
|
21
|
-
puts "Got a 404 response: the queue has already been removed"
|
22
|
-
end
|
23
|
-
|
24
|
-
sleep 0.7
|
25
|
-
puts "Closing..."
|
26
|
-
conn.close
|
@@ -1,32 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "bunny"
|
6
|
-
|
7
|
-
puts "=> Demonstrating sender-selected distribution"
|
8
|
-
puts
|
9
|
-
|
10
|
-
conn = Bunny.new
|
11
|
-
conn.start
|
12
|
-
|
13
|
-
ch = conn.create_channel
|
14
|
-
x = ch.direct("bunny.examples.ssd.exchange")
|
15
|
-
q1 = ch.queue("", :exclusive => true).bind(x, :routing_key => "one")
|
16
|
-
q2 = ch.queue("", :exclusive => true).bind(x, :routing_key => "two")
|
17
|
-
q3 = ch.queue("", :exclusive => true).bind(x, :routing_key => "three")
|
18
|
-
q4 = ch.queue("", :exclusive => true).bind(x, :routing_key => "four")
|
19
|
-
|
20
|
-
10.times do |i|
|
21
|
-
x.publish("Message #{i}", :routing_key => "one", :headers => {"CC" => ["two", "three"]})
|
22
|
-
end
|
23
|
-
|
24
|
-
sleep 0.2
|
25
|
-
puts "Queue #{q1.name} now has #{q1.message_count} messages in it"
|
26
|
-
puts "Queue #{q2.name} now has #{q2.message_count} messages in it"
|
27
|
-
puts "Queue #{q3.name} now has #{q3.message_count} messages in it"
|
28
|
-
puts "Queue #{q4.name} now has #{q4.message_count} messages in it"
|
29
|
-
|
30
|
-
sleep 0.7
|
31
|
-
puts "Closing..."
|
32
|
-
conn.close
|
@@ -1,27 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "bunny"
|
6
|
-
|
7
|
-
conn = Bunny.new
|
8
|
-
conn.start
|
9
|
-
|
10
|
-
ch = conn.create_channel
|
11
|
-
x = ch.fanout("nba.scores")
|
12
|
-
|
13
|
-
ch.queue("joe", :auto_delete => true).bind(x).subscribe do |delivery_info, properties, payload|
|
14
|
-
puts "#{payload} => joe"
|
15
|
-
end
|
16
|
-
|
17
|
-
ch.queue("aaron", :auto_delete => true).bind(x).subscribe do |delivery_info, properties, payload|
|
18
|
-
puts "#{payload} => aaron"
|
19
|
-
end
|
20
|
-
|
21
|
-
ch.queue("bob", :auto_delete => true).bind(x).subscribe do |delivery_info, properties, payload|
|
22
|
-
puts "#{payload} => bob"
|
23
|
-
end
|
24
|
-
|
25
|
-
x.publish("BOS 101, NYK 89").publish("ORL 85, ALT 88")
|
26
|
-
|
27
|
-
conn.close
|
@@ -1,22 +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
|
-
conn = Bunny.new
|
10
|
-
conn.start
|
11
|
-
|
12
|
-
ch = conn.create_channel
|
13
|
-
q = ch.queue("bunny.examples.hello_world", :auto_delete => true)
|
14
|
-
|
15
|
-
q.subscribe do |delivery_info, properties, payload|
|
16
|
-
puts "Received #{payload}"
|
17
|
-
end
|
18
|
-
|
19
|
-
q.publish("Hello!", :routing_key => q.name)
|
20
|
-
|
21
|
-
sleep 1.0
|
22
|
-
conn.close
|
@@ -1,49 +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
|
-
connection = Bunny.new
|
10
|
-
connection.start
|
11
|
-
|
12
|
-
channel = connection.create_channel
|
13
|
-
# topic exchange name can be any string
|
14
|
-
exchange = channel.topic("weathr", :auto_delete => true)
|
15
|
-
|
16
|
-
# Subscribers.
|
17
|
-
channel.queue("", :exclusive => true).bind(exchange, :routing_key => "americas.north.#").subscribe do |delivery_info, properties, payload|
|
18
|
-
puts "An update for North America: #{payload}, routing key is #{delivery_info.routing_key}"
|
19
|
-
end
|
20
|
-
channel.queue("americas.south").bind(exchange, :routing_key => "americas.south.#").subscribe do |delivery_info, properties, payload|
|
21
|
-
puts "An update for South America: #{payload}, routing key is #{delivery_info.routing_key}"
|
22
|
-
end
|
23
|
-
channel.queue("us.california").bind(exchange, :routing_key => "americas.north.us.ca.*").subscribe do |delivery_info, properties, payload|
|
24
|
-
puts "An update for US/California: #{payload}, routing key is #{delivery_info.routing_key}"
|
25
|
-
end
|
26
|
-
channel.queue("us.tx.austin").bind(exchange, :routing_key => "#.tx.austin").subscribe do |delivery_info, properties, payload|
|
27
|
-
puts "An update for Austin, TX: #{payload}, routing key is #{delivery_info.routing_key}"
|
28
|
-
end
|
29
|
-
channel.queue("it.rome").bind(exchange, :routing_key => "europe.italy.rome").subscribe do |delivery_info, properties, payload|
|
30
|
-
puts "An update for Rome, Italy: #{payload}, routing key is #{delivery_info.routing_key}"
|
31
|
-
end
|
32
|
-
channel.queue("asia.hk").bind(exchange, :routing_key => "asia.southeast.hk.#").subscribe do |delivery_info, properties, payload|
|
33
|
-
puts "An update for Hong Kong: #{payload}, routing key is #{delivery_info.routing_key}"
|
34
|
-
end
|
35
|
-
|
36
|
-
exchange.publish("San Diego update", :routing_key => "americas.north.us.ca.sandiego").
|
37
|
-
publish("Berkeley update", :routing_key => "americas.north.us.ca.berkeley").
|
38
|
-
publish("San Francisco update", :routing_key => "americas.north.us.ca.sanfrancisco").
|
39
|
-
publish("New York update", :routing_key => "americas.north.us.ny.newyork").
|
40
|
-
publish("São Paolo update", :routing_key => "americas.south.brazil.saopaolo").
|
41
|
-
publish("Hong Kong update", :routing_key => "asia.southeast.hk.hongkong").
|
42
|
-
publish("Kyoto update", :routing_key => "asia.southeast.japan.kyoto").
|
43
|
-
publish("Shanghai update", :routing_key => "asia.southeast.prc.shanghai").
|
44
|
-
publish("Rome update", :routing_key => "europe.italy.roma").
|
45
|
-
publish("Paris update", :routing_key => "europe.france.paris")
|
46
|
-
|
47
|
-
sleep 1.0
|
48
|
-
|
49
|
-
connection.close
|
@@ -1,25 +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
|
-
conn = Bunny.new
|
10
|
-
conn.start
|
11
|
-
|
12
|
-
ch = conn.create_channel
|
13
|
-
q = ch.queue("bunny.examples.hello_world", :auto_delete => true)
|
14
|
-
|
15
|
-
q.publish("Hello!", :routing_key => q.name)
|
16
|
-
|
17
|
-
# demonstrates a blocking consumer that needs to cancel itself
|
18
|
-
# in the message handler
|
19
|
-
q.subscribe(:block => true) do |delivery_info, properties, payload|
|
20
|
-
puts "Received #{payload}, cancelling"
|
21
|
-
delivery_info.consumer.cancel
|
22
|
-
end
|
23
|
-
|
24
|
-
sleep 1.0
|
25
|
-
conn.close
|
@@ -1,81 +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 "=> Subscribing for messages using explicit acknowledgements model"
|
10
|
-
puts
|
11
|
-
|
12
|
-
connection1 = Bunny.new
|
13
|
-
connection1.start
|
14
|
-
|
15
|
-
connection2 = Bunny.new
|
16
|
-
connection2.start
|
17
|
-
|
18
|
-
connection3 = Bunny.new
|
19
|
-
connection3.start
|
20
|
-
|
21
|
-
ch1 = connection1.create_channel
|
22
|
-
ch1.prefetch(1)
|
23
|
-
|
24
|
-
ch2 = connection2.create_channel
|
25
|
-
ch2.prefetch(1)
|
26
|
-
|
27
|
-
ch3 = connection3.create_channel
|
28
|
-
ch3.prefetch(1)
|
29
|
-
|
30
|
-
x = ch3.direct("amq.direct")
|
31
|
-
q1 = ch1.queue("bunny.examples.acknowledgements.explicit", :auto_delete => false)
|
32
|
-
q1.purge
|
33
|
-
|
34
|
-
q1.bind(x).subscribe(:manual_ack => true, :block => false) do |delivery_info, properties, payload|
|
35
|
-
# do some work
|
36
|
-
sleep(0.2)
|
37
|
-
|
38
|
-
# acknowledge some messages, they will be removed from the queue
|
39
|
-
if rand > 0.5
|
40
|
-
# FYI: there is a shortcut, Bunny::Channel.ack
|
41
|
-
ch1.acknowledge(delivery_info.delivery_tag, false)
|
42
|
-
puts "[consumer1] Got message ##{properties.headers['i']}, redelivered?: #{delivery_info.redelivered?}, ack-ed"
|
43
|
-
else
|
44
|
-
# some messages are not ack-ed and will remain in the queue for redelivery
|
45
|
-
# when app #1 connection is closed (either properly or due to a crash)
|
46
|
-
puts "[consumer1] Got message ##{properties.headers['i']}, SKIPPED"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
q2 = ch2.queue("bunny.examples.acknowledgements.explicit", :auto_delete => false)
|
51
|
-
q2.bind(x).subscribe(:manual_ack => true, :block => false) do |delivery_info, properties, payload|
|
52
|
-
# do some work
|
53
|
-
sleep(0.2)
|
54
|
-
|
55
|
-
ch2.acknowledge(delivery_info.delivery_tag, false)
|
56
|
-
puts "[consumer2] Got message ##{properties.headers['i']}, redelivered?: #{delivery_info.redelivered?}, ack-ed"
|
57
|
-
end
|
58
|
-
|
59
|
-
t1 = Thread.new do
|
60
|
-
i = 0
|
61
|
-
loop do
|
62
|
-
sleep 0.5
|
63
|
-
|
64
|
-
x.publish("Message ##{i}", :headers => { :i => i })
|
65
|
-
i += 1
|
66
|
-
end
|
67
|
-
end
|
68
|
-
t1.abort_on_exception = true
|
69
|
-
|
70
|
-
t2 = Thread.new do
|
71
|
-
sleep 4.0
|
72
|
-
|
73
|
-
connection1.close
|
74
|
-
puts "----- Connection 1 is now closed (we pretend that it has crashed) -----"
|
75
|
-
end
|
76
|
-
t2.abort_on_exception = true
|
77
|
-
|
78
|
-
|
79
|
-
sleep 7.0
|
80
|
-
connection2.close
|
81
|
-
connection3.close
|