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,35 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "bunny"
|
6
|
-
|
7
|
-
puts "=> Demonstrating connection.blocked"
|
8
|
-
puts
|
9
|
-
|
10
|
-
conn = Bunny.new
|
11
|
-
conn.start
|
12
|
-
|
13
|
-
ch = conn.create_channel
|
14
|
-
x = ch.fanout("amq.fanout")
|
15
|
-
|
16
|
-
# This example requires high memory watermark to be set
|
17
|
-
# really low to demonstrate blocking.
|
18
|
-
#
|
19
|
-
# rabbitmqctl set_vm_memory_high_watermark 0.00000001
|
20
|
-
#
|
21
|
-
# should do it.
|
22
|
-
|
23
|
-
conn.on_blocked do |connection_blocked|
|
24
|
-
puts "Connection is blocked. Reason: #{connection_blocked.reason}"
|
25
|
-
end
|
26
|
-
|
27
|
-
conn.on_unblocked do |connection_unblocked|
|
28
|
-
puts "Connection is unblocked."
|
29
|
-
end
|
30
|
-
|
31
|
-
x.publish("z" * 1024 * 1024 * 16)
|
32
|
-
|
33
|
-
sleep 120.0
|
34
|
-
puts "Disconnecting..."
|
35
|
-
conn.close
|
@@ -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
|
@@ -1,33 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require "rubygems"
|
5
|
-
require "bunny"
|
6
|
-
require "ruby-prof"
|
7
|
-
|
8
|
-
conn = Bunny.new
|
9
|
-
conn.start
|
10
|
-
|
11
|
-
puts
|
12
|
-
puts "-" * 80
|
13
|
-
puts "Benchmarking on #{RUBY_DESCRIPTION}"
|
14
|
-
|
15
|
-
n = 50_000
|
16
|
-
ch = conn.create_channel
|
17
|
-
x = ch.default_exchange
|
18
|
-
s = "z" * 4096
|
19
|
-
|
20
|
-
# warm up the JIT, etc
|
21
|
-
puts "Doing a warmup run..."
|
22
|
-
16000.times { x.publish(s, :routing_key => "anything") }
|
23
|
-
|
24
|
-
# give OS, the server and so on some time to catch
|
25
|
-
# up
|
26
|
-
sleep 2.0
|
27
|
-
|
28
|
-
result = RubyProf.profile do
|
29
|
-
n.times { x.publish(s, :routing_key => "anything") }
|
30
|
-
end
|
31
|
-
|
32
|
-
printer = RubyProf::FlatPrinter.new(result)
|
33
|
-
printer.print(STDOUT, {})
|
data/spec/config/enabled_plugins
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
[rabbitmq_management, rabbitmq_consistent_hash_exchange].
|
data/spec/config/rabbitmq.config
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
[
|
2
|
-
|
3
|
-
{rabbit, [
|
4
|
-
{ssl_listeners, [5671]},
|
5
|
-
{ssl_options, [{cacertfile,"/spec/tls/ca_certificate.pem"},
|
6
|
-
{certfile,"/spec/tls/server_certificate.pem"},
|
7
|
-
{keyfile,"/spec/tls/server_key.pem"},
|
8
|
-
{verify,verify_none},
|
9
|
-
{fail_if_no_peer_cert,false}]},
|
10
|
-
{loopback_users, []}
|
11
|
-
] },
|
12
|
-
|
13
|
-
{rabbitmq_management,
|
14
|
-
[{listener,
|
15
|
-
[{port, 15672}]
|
16
|
-
}]
|
17
|
-
}
|
18
|
-
|
19
|
-
].
|