bunny 1.0.7 → 2.24.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 (168) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +92 -87
  3. data/lib/amq/protocol/extensions.rb +2 -0
  4. data/lib/bunny/authentication/credentials_encoder.rb +2 -0
  5. data/lib/bunny/authentication/external_mechanism_encoder.rb +2 -0
  6. data/lib/bunny/authentication/plain_mechanism_encoder.rb +2 -0
  7. data/lib/bunny/channel.rb +485 -186
  8. data/lib/bunny/channel_id_allocator.rb +8 -4
  9. data/lib/bunny/concurrent/atomic_fixnum.rb +2 -0
  10. data/lib/bunny/concurrent/condition.rb +2 -0
  11. data/lib/bunny/concurrent/continuation_queue.rb +37 -13
  12. data/lib/bunny/concurrent/synchronized_sorted_set.rb +2 -0
  13. data/lib/bunny/consumer.rb +20 -13
  14. data/lib/bunny/consumer_tag_generator.rb +6 -2
  15. data/lib/bunny/consumer_work_pool.rb +37 -7
  16. data/lib/bunny/cruby/socket.rb +51 -22
  17. data/lib/bunny/cruby/ssl_socket.rb +68 -5
  18. data/lib/bunny/delivery_info.rb +3 -1
  19. data/lib/bunny/exceptions.rb +27 -4
  20. data/lib/bunny/exchange.rb +35 -29
  21. data/lib/bunny/framing.rb +2 -0
  22. data/lib/bunny/get_response.rb +85 -0
  23. data/lib/bunny/heartbeat_sender.rb +9 -6
  24. data/lib/bunny/message_properties.rb +2 -0
  25. data/lib/bunny/queue.rb +89 -41
  26. data/lib/bunny/reader_loop.rb +72 -28
  27. data/lib/bunny/return_info.rb +2 -0
  28. data/lib/bunny/session.rb +621 -225
  29. data/lib/bunny/socket.rb +7 -12
  30. data/lib/bunny/ssl_socket.rb +7 -12
  31. data/lib/bunny/test_kit.rb +15 -0
  32. data/lib/bunny/timeout.rb +3 -12
  33. data/lib/bunny/timestamp.rb +24 -0
  34. data/lib/bunny/transport.rb +223 -98
  35. data/lib/bunny/version.rb +2 -1
  36. data/lib/bunny/versioned_delivery_tag.rb +2 -0
  37. data/lib/bunny.rb +54 -8
  38. metadata +38 -224
  39. data/.gitignore +0 -22
  40. data/.rspec +0 -3
  41. data/.ruby-version +0 -1
  42. data/.travis.yml +0 -23
  43. data/.yardopts +0 -8
  44. data/ChangeLog.md +0 -1092
  45. data/Gemfile +0 -54
  46. data/LICENSE +0 -21
  47. data/benchmarks/basic_publish/with_128K_messages.rb +0 -35
  48. data/benchmarks/basic_publish/with_1k_messages.rb +0 -35
  49. data/benchmarks/basic_publish/with_4K_messages.rb +0 -35
  50. data/benchmarks/basic_publish/with_64K_messages.rb +0 -35
  51. data/benchmarks/channel_open.rb +0 -28
  52. data/benchmarks/mutex_and_monitor.rb +0 -42
  53. data/benchmarks/queue_declare.rb +0 -29
  54. data/benchmarks/queue_declare_and_bind.rb +0 -29
  55. data/benchmarks/queue_declare_bind_and_delete.rb +0 -29
  56. data/benchmarks/synchronized_sorted_set.rb +0 -53
  57. data/benchmarks/write_vs_write_nonblock.rb +0 -49
  58. data/bin/ci/before_build.sh +0 -31
  59. data/bunny.gemspec +0 -40
  60. data/examples/connection/authentication_failure.rb +0 -16
  61. data/examples/connection/automatic_recovery_with_basic_get.rb +0 -40
  62. data/examples/connection/automatic_recovery_with_client_named_queues.rb +0 -36
  63. data/examples/connection/automatic_recovery_with_multiple_consumers.rb +0 -46
  64. data/examples/connection/automatic_recovery_with_server_named_queues.rb +0 -35
  65. data/examples/connection/channel_level_exception.rb +0 -35
  66. data/examples/connection/disabled_automatic_recovery.rb +0 -34
  67. data/examples/connection/heartbeat.rb +0 -17
  68. data/examples/connection/manually_reconnecting_consumer.rb +0 -23
  69. data/examples/connection/manually_reconnecting_publisher.rb +0 -28
  70. data/examples/connection/unknown_host.rb +0 -16
  71. data/examples/guides/exchanges/direct_exchange_routing.rb +0 -36
  72. data/examples/guides/exchanges/fanout_exchange_routing.rb +0 -28
  73. data/examples/guides/exchanges/headers_exchange_routing.rb +0 -31
  74. data/examples/guides/exchanges/mandatory_messages.rb +0 -30
  75. data/examples/guides/extensions/alternate_exchange.rb +0 -28
  76. data/examples/guides/extensions/basic_nack.rb +0 -33
  77. data/examples/guides/extensions/connection_blocked.rb +0 -35
  78. data/examples/guides/extensions/consumer_cancellation_notification.rb +0 -39
  79. data/examples/guides/extensions/dead_letter_exchange.rb +0 -32
  80. data/examples/guides/extensions/exchange_to_exchange_bindings.rb +0 -29
  81. data/examples/guides/extensions/per_message_ttl.rb +0 -36
  82. data/examples/guides/extensions/per_queue_message_ttl.rb +0 -36
  83. data/examples/guides/extensions/publisher_confirms.rb +0 -28
  84. data/examples/guides/extensions/queue_lease.rb +0 -26
  85. data/examples/guides/extensions/sender_selected_distribution.rb +0 -32
  86. data/examples/guides/getting_started/blabbr.rb +0 -27
  87. data/examples/guides/getting_started/hello_world.rb +0 -20
  88. data/examples/guides/getting_started/weathr.rb +0 -47
  89. data/examples/guides/queues/one_off_consumer.rb +0 -23
  90. data/examples/guides/queues/redeliveries.rb +0 -79
  91. data/lib/bunny/compatibility.rb +0 -24
  92. data/lib/bunny/concurrent/linked_continuation_queue.rb +0 -61
  93. data/lib/bunny/jruby/socket.rb +0 -40
  94. data/lib/bunny/jruby/ssl_socket.rb +0 -53
  95. data/lib/bunny/system_timer.rb +0 -20
  96. data/profiling/basic_publish/with_4K_messages.rb +0 -33
  97. data/repl +0 -3
  98. data/spec/compatibility/queue_declare_spec.rb +0 -44
  99. data/spec/compatibility/queue_declare_with_default_channel_spec.rb +0 -33
  100. data/spec/higher_level_api/integration/basic_ack_spec.rb +0 -71
  101. data/spec/higher_level_api/integration/basic_cancel_spec.rb +0 -76
  102. data/spec/higher_level_api/integration/basic_consume_spec.rb +0 -225
  103. data/spec/higher_level_api/integration/basic_consume_with_objects_spec.rb +0 -54
  104. data/spec/higher_level_api/integration/basic_get_spec.rb +0 -48
  105. data/spec/higher_level_api/integration/basic_nack_spec.rb +0 -79
  106. data/spec/higher_level_api/integration/basic_publish_spec.rb +0 -89
  107. data/spec/higher_level_api/integration/basic_qos_spec.rb +0 -29
  108. data/spec/higher_level_api/integration/basic_recover_spec.rb +0 -18
  109. data/spec/higher_level_api/integration/basic_reject_spec.rb +0 -74
  110. data/spec/higher_level_api/integration/basic_return_spec.rb +0 -33
  111. data/spec/higher_level_api/integration/channel_close_spec.rb +0 -25
  112. data/spec/higher_level_api/integration/channel_flow_spec.rb +0 -21
  113. data/spec/higher_level_api/integration/channel_open_spec.rb +0 -57
  114. data/spec/higher_level_api/integration/confirm_select_spec.rb +0 -19
  115. data/spec/higher_level_api/integration/connection_spec.rb +0 -400
  116. data/spec/higher_level_api/integration/connection_stop_spec.rb +0 -26
  117. data/spec/higher_level_api/integration/consistent_hash_exchange_spec.rb +0 -50
  118. data/spec/higher_level_api/integration/consumer_cancellation_notification_spec.rb +0 -128
  119. data/spec/higher_level_api/integration/dead_lettering_spec.rb +0 -52
  120. data/spec/higher_level_api/integration/exchange_bind_spec.rb +0 -31
  121. data/spec/higher_level_api/integration/exchange_declare_spec.rb +0 -204
  122. data/spec/higher_level_api/integration/exchange_delete_spec.rb +0 -105
  123. data/spec/higher_level_api/integration/exchange_unbind_spec.rb +0 -40
  124. data/spec/higher_level_api/integration/exclusive_queue_spec.rb +0 -28
  125. data/spec/higher_level_api/integration/heartbeat_spec.rb +0 -31
  126. data/spec/higher_level_api/integration/merry_go_round_spec.rb +0 -85
  127. data/spec/higher_level_api/integration/message_properties_access_spec.rb +0 -95
  128. data/spec/higher_level_api/integration/predeclared_exchanges_spec.rb +0 -24
  129. data/spec/higher_level_api/integration/publisher_confirms_spec.rb +0 -77
  130. data/spec/higher_level_api/integration/publishing_edge_cases_spec.rb +0 -65
  131. data/spec/higher_level_api/integration/queue_bind_spec.rb +0 -109
  132. data/spec/higher_level_api/integration/queue_declare_spec.rb +0 -190
  133. data/spec/higher_level_api/integration/queue_delete_spec.rb +0 -41
  134. data/spec/higher_level_api/integration/queue_purge_spec.rb +0 -30
  135. data/spec/higher_level_api/integration/queue_unbind_spec.rb +0 -54
  136. data/spec/higher_level_api/integration/read_only_consumer_spec.rb +0 -60
  137. data/spec/higher_level_api/integration/sender_selected_distribution_spec.rb +0 -36
  138. data/spec/higher_level_api/integration/tls_connection_spec.rb +0 -127
  139. data/spec/higher_level_api/integration/tx_commit_spec.rb +0 -21
  140. data/spec/higher_level_api/integration/tx_rollback_spec.rb +0 -21
  141. data/spec/higher_level_api/integration/with_channel_spec.rb +0 -25
  142. data/spec/issues/issue100_spec.rb +0 -42
  143. data/spec/issues/issue141_spec.rb +0 -44
  144. data/spec/issues/issue78_spec.rb +0 -75
  145. data/spec/issues/issue83_spec.rb +0 -31
  146. data/spec/issues/issue97_attachment.json +0 -1
  147. data/spec/issues/issue97_spec.rb +0 -176
  148. data/spec/lower_level_api/integration/basic_cancel_spec.rb +0 -69
  149. data/spec/lower_level_api/integration/basic_consume_spec.rb +0 -100
  150. data/spec/spec_helper.rb +0 -64
  151. data/spec/stress/channel_open_stress_spec.rb +0 -51
  152. data/spec/stress/channel_open_stress_with_single_threaded_connection_spec.rb +0 -28
  153. data/spec/stress/concurrent_consumers_stress_spec.rb +0 -69
  154. data/spec/stress/concurrent_publishers_stress_spec.rb +0 -57
  155. data/spec/stress/connection_open_close_spec.rb +0 -40
  156. data/spec/stress/long_running_consumer_spec.rb +0 -83
  157. data/spec/tls/cacert.pem +0 -18
  158. data/spec/tls/client_cert.pem +0 -18
  159. data/spec/tls/client_key.pem +0 -27
  160. data/spec/tls/server_cert.pem +0 -18
  161. data/spec/tls/server_key.pem +0 -27
  162. data/spec/unit/bunny_spec.rb +0 -15
  163. data/spec/unit/concurrent/atomic_fixnum_spec.rb +0 -35
  164. data/spec/unit/concurrent/condition_spec.rb +0 -82
  165. data/spec/unit/concurrent/linked_continuation_queue_spec.rb +0 -35
  166. data/spec/unit/concurrent/synchronized_sorted_set_spec.rb +0 -73
  167. data/spec/unit/system_timer_spec.rb +0 -10
  168. data/spec/unit/version_delivery_tag_spec.rb +0 -28
@@ -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,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,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
- begin
15
- ch1 = conn.create_channel
16
- ch1.queue_delete("queue_that_should_not_exist#{rand}")
17
- rescue Bunny::NotFound => e
18
- puts "Channel-level exception! Code: #{e.channel_close.reply_code}, message: #{e.channel_close.reply_text}"
19
- end
20
-
21
-
22
- begin
23
- ch2 = conn.create_channel
24
- q = "bunny.examples.recovery.q#{rand}"
25
-
26
- ch2.queue_declare(q, :durable => false)
27
- ch2.queue_declare(q, :durable => true)
28
- rescue Bunny::PreconditionFailed => e
29
- puts "Channel-level exception! Code: #{e.channel_close.reply_code}, message: #{e.channel_close.reply_text}"
30
- ensure
31
- conn.create_channel.queue_delete(q)
32
- end
33
-
34
- puts "Disconnecting..."
35
- 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,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,28 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
-
4
- require "rubygems"
5
- require "bunny"
6
-
7
- puts "=> Demonstrating alternate exchanges"
8
- puts
9
-
10
- conn = Bunny.new
11
- conn.start
12
-
13
- ch = conn.create_channel
14
- x1 = ch.fanout("bunny.examples.ae.exchange1", :auto_delete => true, :durable => false)
15
- x2 = ch.fanout("bunny.examples.ae.exchange2", :auto_delete => true, :durable => false, :arguments => {
16
- "alternate-exchange" => x1.name
17
- })
18
- q = ch.queue("", :exclusive => true)
19
- q.bind(x1)
20
-
21
- x2.publish("")
22
-
23
- sleep 0.2
24
- puts "Queue #{q.name} now has #{q.message_count} message in it"
25
-
26
- sleep 0.7
27
- puts "Disconnecting..."
28
- 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(: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
@@ -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(: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