bunny 2.14.2 → 2.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +56 -39
  3. data/lib/bunny/channel.rb +89 -13
  4. data/lib/bunny/consumer.rb +2 -2
  5. data/lib/bunny/consumer_work_pool.rb +1 -1
  6. data/lib/bunny/cruby/socket.rb +3 -0
  7. data/lib/bunny/delivery_info.rb +1 -1
  8. data/lib/bunny/queue.rb +36 -5
  9. data/lib/bunny/reader_loop.rb +21 -13
  10. data/lib/bunny/session.rb +83 -25
  11. data/lib/bunny/transport.rb +49 -12
  12. data/lib/bunny/version.rb +1 -1
  13. data/lib/bunny.rb +45 -4
  14. metadata +37 -235
  15. data/.github/ISSUE_TEMPLATE.md +0 -18
  16. data/.gitignore +0 -28
  17. data/.rspec +0 -1
  18. data/.travis.yml +0 -31
  19. data/.yardopts +0 -8
  20. data/CONTRIBUTING.md +0 -132
  21. data/ChangeLog.md +0 -2072
  22. data/Gemfile +0 -55
  23. data/LICENSE +0 -21
  24. data/Rakefile +0 -54
  25. data/benchmarks/basic_publish/with_128K_messages.rb +0 -35
  26. data/benchmarks/basic_publish/with_1k_messages.rb +0 -35
  27. data/benchmarks/basic_publish/with_4K_messages.rb +0 -35
  28. data/benchmarks/basic_publish/with_64K_messages.rb +0 -35
  29. data/benchmarks/channel_open.rb +0 -28
  30. data/benchmarks/mutex_and_monitor.rb +0 -42
  31. data/benchmarks/queue_declare.rb +0 -29
  32. data/benchmarks/queue_declare_and_bind.rb +0 -29
  33. data/benchmarks/queue_declare_bind_and_delete.rb +0 -29
  34. data/benchmarks/synchronized_sorted_set.rb +0 -53
  35. data/benchmarks/write_vs_write_nonblock.rb +0 -49
  36. data/bunny.gemspec +0 -34
  37. data/docker/Dockerfile +0 -20
  38. data/docker/apt/preferences.d/erlang +0 -3
  39. data/docker/apt/sources.list.d/bintray.rabbitmq.list +0 -2
  40. data/docker/docker-entrypoint.sh +0 -26
  41. data/docker/rabbitmq.conf +0 -29
  42. data/docker-compose.yml +0 -28
  43. data/examples/connection/authentication_failure.rb +0 -16
  44. data/examples/connection/automatic_recovery_with_basic_get.rb +0 -40
  45. data/examples/connection/automatic_recovery_with_client_named_queues.rb +0 -36
  46. data/examples/connection/automatic_recovery_with_multiple_consumers.rb +0 -46
  47. data/examples/connection/automatic_recovery_with_republishing.rb +0 -109
  48. data/examples/connection/automatic_recovery_with_server_named_queues.rb +0 -35
  49. data/examples/connection/channel_level_exception.rb +0 -27
  50. data/examples/connection/disabled_automatic_recovery.rb +0 -34
  51. data/examples/connection/heartbeat.rb +0 -17
  52. data/examples/connection/manually_reconnecting_consumer.rb +0 -23
  53. data/examples/connection/manually_reconnecting_publisher.rb +0 -28
  54. data/examples/connection/unknown_host.rb +0 -16
  55. data/examples/consumers/high_and_low_priority.rb +0 -50
  56. data/examples/guides/exchanges/direct_exchange_routing.rb +0 -36
  57. data/examples/guides/exchanges/fanout_exchange_routing.rb +0 -28
  58. data/examples/guides/exchanges/headers_exchange_routing.rb +0 -31
  59. data/examples/guides/exchanges/mandatory_messages.rb +0 -30
  60. data/examples/guides/extensions/alternate_exchange.rb +0 -30
  61. data/examples/guides/extensions/basic_nack.rb +0 -33
  62. data/examples/guides/extensions/connection_blocked.rb +0 -35
  63. data/examples/guides/extensions/consumer_cancellation_notification.rb +0 -39
  64. data/examples/guides/extensions/dead_letter_exchange.rb +0 -32
  65. data/examples/guides/extensions/exchange_to_exchange_bindings.rb +0 -29
  66. data/examples/guides/extensions/per_message_ttl.rb +0 -36
  67. data/examples/guides/extensions/per_queue_message_ttl.rb +0 -36
  68. data/examples/guides/extensions/publisher_confirms.rb +0 -28
  69. data/examples/guides/extensions/queue_lease.rb +0 -26
  70. data/examples/guides/extensions/sender_selected_distribution.rb +0 -32
  71. data/examples/guides/getting_started/blabbr.rb +0 -27
  72. data/examples/guides/getting_started/hello_world.rb +0 -22
  73. data/examples/guides/getting_started/weathr.rb +0 -49
  74. data/examples/guides/queues/one_off_consumer.rb +0 -25
  75. data/examples/guides/queues/redeliveries.rb +0 -81
  76. data/profiling/basic_publish/with_4K_messages.rb +0 -33
  77. data/repl +0 -3
  78. data/spec/config/enabled_plugins +0 -1
  79. data/spec/config/rabbitmq.conf +0 -13
  80. data/spec/higher_level_api/integration/basic_ack_spec.rb +0 -230
  81. data/spec/higher_level_api/integration/basic_cancel_spec.rb +0 -142
  82. data/spec/higher_level_api/integration/basic_consume_spec.rb +0 -349
  83. data/spec/higher_level_api/integration/basic_consume_with_objects_spec.rb +0 -54
  84. data/spec/higher_level_api/integration/basic_get_spec.rb +0 -80
  85. data/spec/higher_level_api/integration/basic_nack_spec.rb +0 -82
  86. data/spec/higher_level_api/integration/basic_publish_spec.rb +0 -74
  87. data/spec/higher_level_api/integration/basic_qos_spec.rb +0 -57
  88. data/spec/higher_level_api/integration/basic_reject_spec.rb +0 -152
  89. data/spec/higher_level_api/integration/basic_return_spec.rb +0 -33
  90. data/spec/higher_level_api/integration/channel_close_spec.rb +0 -66
  91. data/spec/higher_level_api/integration/channel_open_spec.rb +0 -57
  92. data/spec/higher_level_api/integration/connection_recovery_spec.rb +0 -483
  93. data/spec/higher_level_api/integration/connection_spec.rb +0 -563
  94. data/spec/higher_level_api/integration/connection_stop_spec.rb +0 -83
  95. data/spec/higher_level_api/integration/consumer_cancellation_notification_spec.rb +0 -128
  96. data/spec/higher_level_api/integration/dead_lettering_spec.rb +0 -75
  97. data/spec/higher_level_api/integration/exchange_bind_spec.rb +0 -31
  98. data/spec/higher_level_api/integration/exchange_declare_spec.rb +0 -237
  99. data/spec/higher_level_api/integration/exchange_delete_spec.rb +0 -105
  100. data/spec/higher_level_api/integration/exchange_unbind_spec.rb +0 -40
  101. data/spec/higher_level_api/integration/exclusive_queue_spec.rb +0 -28
  102. data/spec/higher_level_api/integration/heartbeat_spec.rb +0 -49
  103. data/spec/higher_level_api/integration/message_properties_access_spec.rb +0 -95
  104. data/spec/higher_level_api/integration/predeclared_exchanges_spec.rb +0 -24
  105. data/spec/higher_level_api/integration/publisher_confirms_spec.rb +0 -191
  106. data/spec/higher_level_api/integration/publishing_edge_cases_spec.rb +0 -87
  107. data/spec/higher_level_api/integration/queue_bind_spec.rb +0 -109
  108. data/spec/higher_level_api/integration/queue_declare_spec.rb +0 -285
  109. data/spec/higher_level_api/integration/queue_delete_spec.rb +0 -41
  110. data/spec/higher_level_api/integration/queue_purge_spec.rb +0 -30
  111. data/spec/higher_level_api/integration/queue_unbind_spec.rb +0 -54
  112. data/spec/higher_level_api/integration/read_only_consumer_spec.rb +0 -60
  113. data/spec/higher_level_api/integration/sender_selected_distribution_spec.rb +0 -36
  114. data/spec/higher_level_api/integration/tls_connection_spec.rb +0 -250
  115. data/spec/higher_level_api/integration/toxiproxy_spec.rb +0 -76
  116. data/spec/higher_level_api/integration/tx_commit_spec.rb +0 -21
  117. data/spec/higher_level_api/integration/tx_rollback_spec.rb +0 -21
  118. data/spec/higher_level_api/integration/with_channel_spec.rb +0 -25
  119. data/spec/issues/issue100_spec.rb +0 -42
  120. data/spec/issues/issue141_spec.rb +0 -43
  121. data/spec/issues/issue202_spec.rb +0 -15
  122. data/spec/issues/issue224_spec.rb +0 -40
  123. data/spec/issues/issue465_spec.rb +0 -32
  124. data/spec/issues/issue549_spec.rb +0 -30
  125. data/spec/issues/issue78_spec.rb +0 -72
  126. data/spec/issues/issue83_spec.rb +0 -30
  127. data/spec/issues/issue97_attachment.json +0 -1
  128. data/spec/issues/issue97_spec.rb +0 -175
  129. data/spec/lower_level_api/integration/basic_cancel_spec.rb +0 -83
  130. data/spec/lower_level_api/integration/basic_consume_spec.rb +0 -99
  131. data/spec/spec_helper.rb +0 -47
  132. data/spec/stress/channel_close_stress_spec.rb +0 -64
  133. data/spec/stress/channel_open_stress_spec.rb +0 -84
  134. data/spec/stress/channel_open_stress_with_single_threaded_connection_spec.rb +0 -28
  135. data/spec/stress/concurrent_consumers_stress_spec.rb +0 -71
  136. data/spec/stress/concurrent_publishers_stress_spec.rb +0 -54
  137. data/spec/stress/connection_open_close_spec.rb +0 -52
  138. data/spec/stress/merry_go_round_spec.rb +0 -105
  139. data/spec/tls/ca_certificate.pem +0 -29
  140. data/spec/tls/ca_key.pem +0 -52
  141. data/spec/tls/client_certificate.pem +0 -29
  142. data/spec/tls/client_key.pem +0 -51
  143. data/spec/tls/generate-server-cert.sh +0 -8
  144. data/spec/tls/server-openssl.cnf +0 -10
  145. data/spec/tls/server.csr +0 -16
  146. data/spec/tls/server_certificate.pem +0 -29
  147. data/spec/tls/server_key.pem +0 -51
  148. data/spec/toxiproxy_helper.rb +0 -28
  149. data/spec/unit/bunny_spec.rb +0 -15
  150. data/spec/unit/concurrent/atomic_fixnum_spec.rb +0 -35
  151. data/spec/unit/concurrent/condition_spec.rb +0 -82
  152. data/spec/unit/concurrent/linked_continuation_queue_spec.rb +0 -35
  153. data/spec/unit/concurrent/synchronized_sorted_set_spec.rb +0 -73
  154. data/spec/unit/exchange_recovery_spec.rb +0 -39
  155. data/spec/unit/version_delivery_tag_spec.rb +0 -28
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