bunny 2.17.0 → 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.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +30 -11
  3. data/lib/bunny/channel.rb +1 -1
  4. data/lib/bunny/session.rb +22 -4
  5. data/lib/bunny/transport.rb +7 -6
  6. data/lib/bunny/version.rb +1 -1
  7. data/spec/higher_level_api/integration/basic_consume_spec.rb +14 -6
  8. data/spec/higher_level_api/integration/tls_connection_spec.rb +25 -32
  9. data/spec/issues/issue609_spec.rb +84 -0
  10. data/spec/lower_level_api/integration/basic_cancel_spec.rb +1 -1
  11. data/spec/lower_level_api/integration/basic_consume_spec.rb +8 -8
  12. metadata +28 -87
  13. data/.github/ISSUE_TEMPLATE.md +0 -18
  14. data/.gitignore +0 -28
  15. data/.rspec +0 -1
  16. data/.travis.yml +0 -33
  17. data/.yardopts +0 -8
  18. data/CONTRIBUTING.md +0 -132
  19. data/ChangeLog.md +0 -2129
  20. data/Gemfile +0 -55
  21. data/LICENSE +0 -21
  22. data/Rakefile +0 -54
  23. data/benchmarks/basic_publish/with_128K_messages.rb +0 -35
  24. data/benchmarks/basic_publish/with_1k_messages.rb +0 -35
  25. data/benchmarks/basic_publish/with_4K_messages.rb +0 -35
  26. data/benchmarks/basic_publish/with_64K_messages.rb +0 -35
  27. data/benchmarks/channel_open.rb +0 -28
  28. data/benchmarks/mutex_and_monitor.rb +0 -42
  29. data/benchmarks/queue_declare.rb +0 -29
  30. data/benchmarks/queue_declare_and_bind.rb +0 -29
  31. data/benchmarks/queue_declare_bind_and_delete.rb +0 -29
  32. data/benchmarks/synchronized_sorted_set.rb +0 -53
  33. data/benchmarks/write_vs_write_nonblock.rb +0 -49
  34. data/bunny.gemspec +0 -34
  35. data/docker/Dockerfile +0 -24
  36. data/docker/apt/preferences.d/erlang +0 -3
  37. data/docker/apt/sources.list.d/bintray.rabbitmq.list +0 -2
  38. data/docker/docker-entrypoint.sh +0 -26
  39. data/docker/rabbitmq.conf +0 -29
  40. data/docker-compose.yml +0 -28
  41. data/examples/connection/authentication_failure.rb +0 -16
  42. data/examples/connection/automatic_recovery_with_basic_get.rb +0 -40
  43. data/examples/connection/automatic_recovery_with_client_named_queues.rb +0 -36
  44. data/examples/connection/automatic_recovery_with_multiple_consumers.rb +0 -46
  45. data/examples/connection/automatic_recovery_with_republishing.rb +0 -109
  46. data/examples/connection/automatic_recovery_with_server_named_queues.rb +0 -35
  47. data/examples/connection/channel_level_exception.rb +0 -27
  48. data/examples/connection/disabled_automatic_recovery.rb +0 -34
  49. data/examples/connection/heartbeat.rb +0 -17
  50. data/examples/connection/manually_reconnecting_consumer.rb +0 -23
  51. data/examples/connection/manually_reconnecting_publisher.rb +0 -28
  52. data/examples/connection/unknown_host.rb +0 -16
  53. data/examples/consumers/high_and_low_priority.rb +0 -50
  54. data/examples/guides/exchanges/direct_exchange_routing.rb +0 -36
  55. data/examples/guides/exchanges/fanout_exchange_routing.rb +0 -28
  56. data/examples/guides/exchanges/headers_exchange_routing.rb +0 -31
  57. data/examples/guides/exchanges/mandatory_messages.rb +0 -30
  58. data/examples/guides/extensions/alternate_exchange.rb +0 -30
  59. data/examples/guides/extensions/basic_nack.rb +0 -33
  60. data/examples/guides/extensions/connection_blocked.rb +0 -35
  61. data/examples/guides/extensions/consumer_cancellation_notification.rb +0 -39
  62. data/examples/guides/extensions/dead_letter_exchange.rb +0 -32
  63. data/examples/guides/extensions/exchange_to_exchange_bindings.rb +0 -29
  64. data/examples/guides/extensions/per_message_ttl.rb +0 -36
  65. data/examples/guides/extensions/per_queue_message_ttl.rb +0 -36
  66. data/examples/guides/extensions/publisher_confirms.rb +0 -28
  67. data/examples/guides/extensions/queue_lease.rb +0 -26
  68. data/examples/guides/extensions/sender_selected_distribution.rb +0 -32
  69. data/examples/guides/getting_started/blabbr.rb +0 -27
  70. data/examples/guides/getting_started/hello_world.rb +0 -22
  71. data/examples/guides/getting_started/weathr.rb +0 -49
  72. data/examples/guides/queues/one_off_consumer.rb +0 -25
  73. data/examples/guides/queues/redeliveries.rb +0 -81
  74. data/profiling/basic_publish/with_4K_messages.rb +0 -33
  75. data/repl +0 -3
  76. data/spec/tls/ca_certificate.pem +0 -29
  77. data/spec/tls/ca_key.pem +0 -52
  78. data/spec/tls/client_certificate.pem +0 -29
  79. data/spec/tls/client_key.pem +0 -51
  80. data/spec/tls/generate-server-cert.sh +0 -8
  81. data/spec/tls/server-openssl.cnf +0 -10
  82. data/spec/tls/server.csr +0 -16
  83. data/spec/tls/server_certificate.pem +0 -29
  84. data/spec/tls/server_key.pem +0 -51
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
@@ -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
@@ -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_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("", :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_timeout: 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_timeout: 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_timeout => 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_timeout: 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