bunny 2.19.0 → 2.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +31 -32
  3. data/lib/bunny/channel.rb +88 -12
  4. data/lib/bunny/consumer.rb +2 -2
  5. data/lib/bunny/consumer_work_pool.rb +1 -1
  6. data/lib/bunny/delivery_info.rb +1 -1
  7. data/lib/bunny/queue.rb +36 -2
  8. data/lib/bunny/session.rb +39 -16
  9. data/lib/bunny/transport.rb +37 -1
  10. data/lib/bunny/version.rb +1 -1
  11. data/lib/bunny.rb +45 -4
  12. metadata +6 -146
  13. data/spec/config/enabled_plugins +0 -1
  14. data/spec/config/rabbitmq.conf +0 -13
  15. data/spec/higher_level_api/integration/basic_ack_spec.rb +0 -230
  16. data/spec/higher_level_api/integration/basic_cancel_spec.rb +0 -142
  17. data/spec/higher_level_api/integration/basic_consume_spec.rb +0 -357
  18. data/spec/higher_level_api/integration/basic_consume_with_objects_spec.rb +0 -54
  19. data/spec/higher_level_api/integration/basic_get_spec.rb +0 -80
  20. data/spec/higher_level_api/integration/basic_nack_spec.rb +0 -82
  21. data/spec/higher_level_api/integration/basic_publish_spec.rb +0 -74
  22. data/spec/higher_level_api/integration/basic_qos_spec.rb +0 -57
  23. data/spec/higher_level_api/integration/basic_reject_spec.rb +0 -152
  24. data/spec/higher_level_api/integration/basic_return_spec.rb +0 -33
  25. data/spec/higher_level_api/integration/channel_close_spec.rb +0 -66
  26. data/spec/higher_level_api/integration/channel_open_spec.rb +0 -57
  27. data/spec/higher_level_api/integration/connection_recovery_spec.rb +0 -483
  28. data/spec/higher_level_api/integration/connection_spec.rb +0 -589
  29. data/spec/higher_level_api/integration/connection_stop_spec.rb +0 -83
  30. data/spec/higher_level_api/integration/consumer_cancellation_notification_spec.rb +0 -128
  31. data/spec/higher_level_api/integration/dead_lettering_spec.rb +0 -75
  32. data/spec/higher_level_api/integration/exchange_bind_spec.rb +0 -31
  33. data/spec/higher_level_api/integration/exchange_declare_spec.rb +0 -237
  34. data/spec/higher_level_api/integration/exchange_delete_spec.rb +0 -105
  35. data/spec/higher_level_api/integration/exchange_unbind_spec.rb +0 -40
  36. data/spec/higher_level_api/integration/exclusive_queue_spec.rb +0 -28
  37. data/spec/higher_level_api/integration/heartbeat_spec.rb +0 -49
  38. data/spec/higher_level_api/integration/message_properties_access_spec.rb +0 -95
  39. data/spec/higher_level_api/integration/predeclared_exchanges_spec.rb +0 -24
  40. data/spec/higher_level_api/integration/publisher_confirms_spec.rb +0 -191
  41. data/spec/higher_level_api/integration/publishing_edge_cases_spec.rb +0 -87
  42. data/spec/higher_level_api/integration/queue_bind_spec.rb +0 -109
  43. data/spec/higher_level_api/integration/queue_declare_spec.rb +0 -285
  44. data/spec/higher_level_api/integration/queue_delete_spec.rb +0 -41
  45. data/spec/higher_level_api/integration/queue_purge_spec.rb +0 -30
  46. data/spec/higher_level_api/integration/queue_unbind_spec.rb +0 -54
  47. data/spec/higher_level_api/integration/read_only_consumer_spec.rb +0 -60
  48. data/spec/higher_level_api/integration/sender_selected_distribution_spec.rb +0 -36
  49. data/spec/higher_level_api/integration/tls_connection_spec.rb +0 -255
  50. data/spec/higher_level_api/integration/toxiproxy_spec.rb +0 -76
  51. data/spec/higher_level_api/integration/tx_commit_spec.rb +0 -21
  52. data/spec/higher_level_api/integration/tx_rollback_spec.rb +0 -21
  53. data/spec/higher_level_api/integration/with_channel_spec.rb +0 -25
  54. data/spec/issues/issue100_spec.rb +0 -42
  55. data/spec/issues/issue141_spec.rb +0 -43
  56. data/spec/issues/issue202_spec.rb +0 -15
  57. data/spec/issues/issue224_spec.rb +0 -40
  58. data/spec/issues/issue465_spec.rb +0 -32
  59. data/spec/issues/issue549_spec.rb +0 -30
  60. data/spec/issues/issue609_spec.rb +0 -84
  61. data/spec/issues/issue78_spec.rb +0 -72
  62. data/spec/issues/issue83_spec.rb +0 -30
  63. data/spec/issues/issue97_attachment.json +0 -1
  64. data/spec/issues/issue97_spec.rb +0 -175
  65. data/spec/lower_level_api/integration/basic_cancel_spec.rb +0 -83
  66. data/spec/lower_level_api/integration/basic_consume_spec.rb +0 -99
  67. data/spec/spec_helper.rb +0 -47
  68. data/spec/stress/channel_close_stress_spec.rb +0 -64
  69. data/spec/stress/channel_open_stress_spec.rb +0 -84
  70. data/spec/stress/channel_open_stress_with_single_threaded_connection_spec.rb +0 -28
  71. data/spec/stress/concurrent_consumers_stress_spec.rb +0 -71
  72. data/spec/stress/concurrent_publishers_stress_spec.rb +0 -54
  73. data/spec/stress/connection_open_close_spec.rb +0 -52
  74. data/spec/stress/merry_go_round_spec.rb +0 -105
  75. data/spec/toxiproxy_helper.rb +0 -28
  76. data/spec/unit/bunny_spec.rb +0 -15
  77. data/spec/unit/concurrent/atomic_fixnum_spec.rb +0 -35
  78. data/spec/unit/concurrent/condition_spec.rb +0 -82
  79. data/spec/unit/concurrent/linked_continuation_queue_spec.rb +0 -35
  80. data/spec/unit/concurrent/synchronized_sorted_set_spec.rb +0 -73
  81. data/spec/unit/exchange_recovery_spec.rb +0 -39
  82. data/spec/unit/version_delivery_tag_spec.rb +0 -28
data/lib/bunny.rb CHANGED
@@ -53,17 +53,58 @@ module Bunny
53
53
  # Instantiates a new connection. The actual network
54
54
  # connection is started with {Bunny::Session#start}
55
55
  #
56
+ # @param [String, Hash] connection_string_or_opts Connection string or a hash of connection options
57
+ # @param [Hash] optz Extra options not related to connection
58
+ #
59
+ # @option connection_string_or_opts [String] :host ("127.0.0.1") Hostname or IP address to connect to
60
+ # @option connection_string_or_opts [Array<String>] :hosts (["127.0.0.1"]) list of hostname or IP addresses to select hostname from when connecting
61
+ # @option connection_string_or_opts [Array<String>] :addresses (["127.0.0.1:5672"]) list of addresses to select hostname and port from when connecting
62
+ # @option connection_string_or_opts [Integer] :port (5672) Port RabbitMQ listens on
63
+ # @option connection_string_or_opts [String] :username ("guest") Username
64
+ # @option connection_string_or_opts [String] :password ("guest") Password
65
+ # @option connection_string_or_opts [String] :vhost ("/") Virtual host to use
66
+ # @option connection_string_or_opts [Integer, Symbol] :heartbeat (:server) Heartbeat timeout to offer to the server. :server means use the value suggested by RabbitMQ. 0 means heartbeats and socket read timeouts will be disabled (not recommended).
67
+ # @option connection_string_or_opts [Integer] :network_recovery_interval (4) Recovery interval periodic network recovery will use. This includes initial pause after network failure.
68
+ # @option connection_string_or_opts [Boolean] :tls (false) Should TLS/SSL be used?
69
+ # @option connection_string_or_opts [String] :tls_cert (nil) Path to client TLS/SSL certificate file (.pem)
70
+ # @option connection_string_or_opts [String] :tls_key (nil) Path to client TLS/SSL private key file (.pem)
71
+ # @option connection_string_or_opts [Array<String>] :tls_ca_certificates Array of paths to TLS/SSL CA files (.pem), by default detected from OpenSSL configuration
72
+ # @option connection_string_or_opts [String] :verify_peer (true) Whether TLS peer verification should be performed
73
+ # @option connection_string_or_opts [Symbol] :tls_protocol (negotiated) What TLS version should be used (:TLSv1, :TLSv1_1, or :TLSv1_2)
74
+ # @option connection_string_or_opts [Integer] :channel_max (2047) Maximum number of channels allowed on this connection, minus 1 to account for the special channel 0.
75
+ # @option connection_string_or_opts [Integer] :continuation_timeout (15000) Timeout for client operations that expect a response (e.g. {Bunny::Queue#get}), in milliseconds.
76
+ # @option connection_string_or_opts [Integer] :connection_timeout (30) Timeout in seconds for connecting to the server.
77
+ # @option connection_string_or_opts [Integer] :read_timeout (30) TCP socket read timeout in seconds. If heartbeats are disabled this will be ignored.
78
+ # @option connection_string_or_opts [Integer] :write_timeout (30) TCP socket write timeout in seconds.
79
+ # @option connection_string_or_opts [Proc] :hosts_shuffle_strategy a callable that reorders a list of host strings, defaults to Array#shuffle
80
+ # @option connection_string_or_opts [Proc] :recovery_completed a callable that will be called when a network recovery is performed
81
+ # @option connection_string_or_opts [Logger] :logger The logger. If missing, one is created using :log_file and :log_level.
82
+ # @option connection_string_or_opts [IO, String] :log_file The file or path to use when creating a logger. Defaults to STDOUT.
83
+ # @option connection_string_or_opts [IO, String] :logfile DEPRECATED: use :log_file instead. The file or path to use when creating a logger. Defaults to STDOUT.
84
+ # @option connection_string_or_opts [Integer] :log_level The log level to use when creating a logger. Defaults to LOGGER::WARN
85
+ # @option connection_string_or_opts [Boolean] :automatically_recover (true) Should automatically recover from network failures?
86
+ # @option connection_string_or_opts [Integer] :recovery_attempts (nil) Max number of recovery attempts, nil means forever
87
+ # @option connection_string_or_opts [Integer] :reset_recovery_attempts_after_reconnection (true) Should recovery attempt counter be reset after successful reconnection? When set to false, the attempt counter will last through the entire lifetime of the connection object.
88
+ # @option connection_string_or_opts [Proc] :recovery_attempt_started (nil) Will be called before every connection recovery attempt
89
+ # @option connection_string_or_opts [Proc] :recovery_completed (nil) Will be called after successful connection recovery
90
+ # @option connection_string_or_opts [Boolean] :recover_from_connection_close (true) Should this connection recover after receiving a server-sent connection.close (e.g. connection was force closed)?
91
+ # @option connection_string_or_opts [Object] :session_error_handler (Thread.current) Object which responds to #raise that will act as a session error handler. Defaults to Thread.current, which will raise asynchronous exceptions in the thread that created the session.
92
+ #
93
+ # @option optz [String] :auth_mechanism ("PLAIN") Authentication mechanism, PLAIN or EXTERNAL
94
+ # @option optz [String] :locale ("PLAIN") Locale RabbitMQ should use
95
+ # @option optz [String] :connection_name (nil) Client-provided connection name, if any. Note that the value returned does not uniquely identify a connection and cannot be used as a connection identifier in HTTP API requests.
96
+ #
56
97
  # @return [Bunny::Session]
57
98
  # @see Bunny::Session#start
58
99
  # @see http://rubybunny.info/articles/getting_started.html
59
100
  # @see http://rubybunny.info/articles/connecting.html
60
101
  # @api public
61
- def self.new(connection_string_or_opts = ENV['RABBITMQ_URL'], opts = {})
62
- if connection_string_or_opts.respond_to?(:keys) && opts.empty?
63
- opts = connection_string_or_opts
102
+ def self.new(connection_string_or_opts = ENV['RABBITMQ_URL'], optz = {})
103
+ if connection_string_or_opts.respond_to?(:keys) && optz.empty?
104
+ optz = connection_string_or_opts
64
105
  end
65
106
 
66
- conn = Session.new(connection_string_or_opts, opts)
107
+ conn = Session.new(connection_string_or_opts, optz)
67
108
  @default_connection ||= conn
68
109
 
69
110
  conn
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bunny
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.19.0
4
+ version: 2.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Duncan
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2021-06-25 00:00:00.000000000 Z
15
+ date: 2023-06-12 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: amq-protocol
@@ -54,7 +54,7 @@ dependencies:
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
56
  version: 1.0.2
57
- description: Easy to use, feature complete Ruby client for RabbitMQ 3.3 and later
57
+ description: Easy to use, feature complete Ruby client for RabbitMQ 3.9 and later
58
58
  versions.
59
59
  email:
60
60
  - michael.s.klishin@gmail.com
@@ -101,76 +101,6 @@ files:
101
101
  - lib/bunny/transport.rb
102
102
  - lib/bunny/version.rb
103
103
  - lib/bunny/versioned_delivery_tag.rb
104
- - spec/config/enabled_plugins
105
- - spec/config/rabbitmq.conf
106
- - spec/higher_level_api/integration/basic_ack_spec.rb
107
- - spec/higher_level_api/integration/basic_cancel_spec.rb
108
- - spec/higher_level_api/integration/basic_consume_spec.rb
109
- - spec/higher_level_api/integration/basic_consume_with_objects_spec.rb
110
- - spec/higher_level_api/integration/basic_get_spec.rb
111
- - spec/higher_level_api/integration/basic_nack_spec.rb
112
- - spec/higher_level_api/integration/basic_publish_spec.rb
113
- - spec/higher_level_api/integration/basic_qos_spec.rb
114
- - spec/higher_level_api/integration/basic_reject_spec.rb
115
- - spec/higher_level_api/integration/basic_return_spec.rb
116
- - spec/higher_level_api/integration/channel_close_spec.rb
117
- - spec/higher_level_api/integration/channel_open_spec.rb
118
- - spec/higher_level_api/integration/connection_recovery_spec.rb
119
- - spec/higher_level_api/integration/connection_spec.rb
120
- - spec/higher_level_api/integration/connection_stop_spec.rb
121
- - spec/higher_level_api/integration/consumer_cancellation_notification_spec.rb
122
- - spec/higher_level_api/integration/dead_lettering_spec.rb
123
- - spec/higher_level_api/integration/exchange_bind_spec.rb
124
- - spec/higher_level_api/integration/exchange_declare_spec.rb
125
- - spec/higher_level_api/integration/exchange_delete_spec.rb
126
- - spec/higher_level_api/integration/exchange_unbind_spec.rb
127
- - spec/higher_level_api/integration/exclusive_queue_spec.rb
128
- - spec/higher_level_api/integration/heartbeat_spec.rb
129
- - spec/higher_level_api/integration/message_properties_access_spec.rb
130
- - spec/higher_level_api/integration/predeclared_exchanges_spec.rb
131
- - spec/higher_level_api/integration/publisher_confirms_spec.rb
132
- - spec/higher_level_api/integration/publishing_edge_cases_spec.rb
133
- - spec/higher_level_api/integration/queue_bind_spec.rb
134
- - spec/higher_level_api/integration/queue_declare_spec.rb
135
- - spec/higher_level_api/integration/queue_delete_spec.rb
136
- - spec/higher_level_api/integration/queue_purge_spec.rb
137
- - spec/higher_level_api/integration/queue_unbind_spec.rb
138
- - spec/higher_level_api/integration/read_only_consumer_spec.rb
139
- - spec/higher_level_api/integration/sender_selected_distribution_spec.rb
140
- - spec/higher_level_api/integration/tls_connection_spec.rb
141
- - spec/higher_level_api/integration/toxiproxy_spec.rb
142
- - spec/higher_level_api/integration/tx_commit_spec.rb
143
- - spec/higher_level_api/integration/tx_rollback_spec.rb
144
- - spec/higher_level_api/integration/with_channel_spec.rb
145
- - spec/issues/issue100_spec.rb
146
- - spec/issues/issue141_spec.rb
147
- - spec/issues/issue202_spec.rb
148
- - spec/issues/issue224_spec.rb
149
- - spec/issues/issue465_spec.rb
150
- - spec/issues/issue549_spec.rb
151
- - spec/issues/issue609_spec.rb
152
- - spec/issues/issue78_spec.rb
153
- - spec/issues/issue83_spec.rb
154
- - spec/issues/issue97_attachment.json
155
- - spec/issues/issue97_spec.rb
156
- - spec/lower_level_api/integration/basic_cancel_spec.rb
157
- - spec/lower_level_api/integration/basic_consume_spec.rb
158
- - spec/spec_helper.rb
159
- - spec/stress/channel_close_stress_spec.rb
160
- - spec/stress/channel_open_stress_spec.rb
161
- - spec/stress/channel_open_stress_with_single_threaded_connection_spec.rb
162
- - spec/stress/concurrent_consumers_stress_spec.rb
163
- - spec/stress/concurrent_publishers_stress_spec.rb
164
- - spec/stress/connection_open_close_spec.rb
165
- - spec/stress/merry_go_round_spec.rb
166
- - spec/toxiproxy_helper.rb
167
- - spec/unit/bunny_spec.rb
168
- - spec/unit/concurrent/atomic_fixnum_spec.rb
169
- - spec/unit/concurrent/condition_spec.rb
170
- - spec/unit/concurrent/linked_continuation_queue_spec.rb
171
- - spec/unit/concurrent/synchronized_sorted_set_spec.rb
172
- - spec/unit/exchange_recovery_spec.rb
173
- - spec/unit/version_delivery_tag_spec.rb
174
104
  homepage: http://rubybunny.info
175
105
  licenses:
176
106
  - MIT
@@ -183,85 +113,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
113
  requirements:
184
114
  - - ">="
185
115
  - !ruby/object:Gem::Version
186
- version: '2.2'
116
+ version: '2.5'
187
117
  required_rubygems_version: !ruby/object:Gem::Requirement
188
118
  requirements:
189
119
  - - ">="
190
120
  - !ruby/object:Gem::Version
191
121
  version: '0'
192
122
  requirements: []
193
- rubygems_version: 3.1.4
123
+ rubygems_version: 3.5.0.dev
194
124
  signing_key:
195
125
  specification_version: 4
196
126
  summary: Popular easy to use Ruby client for RabbitMQ
197
- test_files:
198
- - spec/config/enabled_plugins
199
- - spec/config/rabbitmq.conf
200
- - spec/higher_level_api/integration/basic_ack_spec.rb
201
- - spec/higher_level_api/integration/basic_cancel_spec.rb
202
- - spec/higher_level_api/integration/basic_consume_spec.rb
203
- - spec/higher_level_api/integration/basic_consume_with_objects_spec.rb
204
- - spec/higher_level_api/integration/basic_get_spec.rb
205
- - spec/higher_level_api/integration/basic_nack_spec.rb
206
- - spec/higher_level_api/integration/basic_publish_spec.rb
207
- - spec/higher_level_api/integration/basic_qos_spec.rb
208
- - spec/higher_level_api/integration/basic_reject_spec.rb
209
- - spec/higher_level_api/integration/basic_return_spec.rb
210
- - spec/higher_level_api/integration/channel_close_spec.rb
211
- - spec/higher_level_api/integration/channel_open_spec.rb
212
- - spec/higher_level_api/integration/connection_recovery_spec.rb
213
- - spec/higher_level_api/integration/connection_spec.rb
214
- - spec/higher_level_api/integration/connection_stop_spec.rb
215
- - spec/higher_level_api/integration/consumer_cancellation_notification_spec.rb
216
- - spec/higher_level_api/integration/dead_lettering_spec.rb
217
- - spec/higher_level_api/integration/exchange_bind_spec.rb
218
- - spec/higher_level_api/integration/exchange_declare_spec.rb
219
- - spec/higher_level_api/integration/exchange_delete_spec.rb
220
- - spec/higher_level_api/integration/exchange_unbind_spec.rb
221
- - spec/higher_level_api/integration/exclusive_queue_spec.rb
222
- - spec/higher_level_api/integration/heartbeat_spec.rb
223
- - spec/higher_level_api/integration/message_properties_access_spec.rb
224
- - spec/higher_level_api/integration/predeclared_exchanges_spec.rb
225
- - spec/higher_level_api/integration/publisher_confirms_spec.rb
226
- - spec/higher_level_api/integration/publishing_edge_cases_spec.rb
227
- - spec/higher_level_api/integration/queue_bind_spec.rb
228
- - spec/higher_level_api/integration/queue_declare_spec.rb
229
- - spec/higher_level_api/integration/queue_delete_spec.rb
230
- - spec/higher_level_api/integration/queue_purge_spec.rb
231
- - spec/higher_level_api/integration/queue_unbind_spec.rb
232
- - spec/higher_level_api/integration/read_only_consumer_spec.rb
233
- - spec/higher_level_api/integration/sender_selected_distribution_spec.rb
234
- - spec/higher_level_api/integration/tls_connection_spec.rb
235
- - spec/higher_level_api/integration/toxiproxy_spec.rb
236
- - spec/higher_level_api/integration/tx_commit_spec.rb
237
- - spec/higher_level_api/integration/tx_rollback_spec.rb
238
- - spec/higher_level_api/integration/with_channel_spec.rb
239
- - spec/issues/issue100_spec.rb
240
- - spec/issues/issue141_spec.rb
241
- - spec/issues/issue202_spec.rb
242
- - spec/issues/issue224_spec.rb
243
- - spec/issues/issue465_spec.rb
244
- - spec/issues/issue549_spec.rb
245
- - spec/issues/issue609_spec.rb
246
- - spec/issues/issue78_spec.rb
247
- - spec/issues/issue83_spec.rb
248
- - spec/issues/issue97_attachment.json
249
- - spec/issues/issue97_spec.rb
250
- - spec/lower_level_api/integration/basic_cancel_spec.rb
251
- - spec/lower_level_api/integration/basic_consume_spec.rb
252
- - spec/spec_helper.rb
253
- - spec/stress/channel_close_stress_spec.rb
254
- - spec/stress/channel_open_stress_spec.rb
255
- - spec/stress/channel_open_stress_with_single_threaded_connection_spec.rb
256
- - spec/stress/concurrent_consumers_stress_spec.rb
257
- - spec/stress/concurrent_publishers_stress_spec.rb
258
- - spec/stress/connection_open_close_spec.rb
259
- - spec/stress/merry_go_round_spec.rb
260
- - spec/toxiproxy_helper.rb
261
- - spec/unit/bunny_spec.rb
262
- - spec/unit/concurrent/atomic_fixnum_spec.rb
263
- - spec/unit/concurrent/condition_spec.rb
264
- - spec/unit/concurrent/linked_continuation_queue_spec.rb
265
- - spec/unit/concurrent/synchronized_sorted_set_spec.rb
266
- - spec/unit/exchange_recovery_spec.rb
267
- - spec/unit/version_delivery_tag_spec.rb
127
+ test_files: []
@@ -1 +0,0 @@
1
- [rabbitmq_management, rabbitmq_consistent_hash_exchange].
@@ -1,13 +0,0 @@
1
- listeners.tcp.1 = 0.0.0.0:5672
2
-
3
- listeners.ssl.default = 5671
4
-
5
- # mounted by docker-compose
6
- ssl_options.cacertfile = /spec/tls/ca_certificate.pem
7
- ssl_options.certfile = /spec/tls/server_certificate.pem
8
- ssl_options.keyfile = /spec/tls/server_key.pem
9
-
10
- ssl_options.verify = verify_none
11
- ssl_options.fail_if_no_peer_cert = false
12
-
13
- loopback_users = none
@@ -1,230 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Bunny::Channel, "#ack" do
4
- let(:connection) do
5
- c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
6
- c.start
7
- c
8
- end
9
-
10
- after :each do
11
- connection.close if connection.open?
12
- end
13
-
14
- context "with a valid (known) delivery tag" do
15
- it "acknowledges a message" do
16
- ch = connection.create_channel
17
- q = ch.queue("bunny.basic.ack.manual-acks", exclusive: true)
18
- x = ch.default_exchange
19
-
20
- x.publish("bunneth", routing_key: q.name)
21
- sleep 0.5
22
- expect(q.message_count).to eq 1
23
- delivery_details, properties, content = q.pop(manual_ack: true)
24
-
25
- ch.ack(delivery_details.delivery_tag, true)
26
- ch.close
27
-
28
- ch = connection.create_channel
29
- q = ch.queue("bunny.basic.ack.manual-acks", exclusive: true)
30
- expect(q.message_count).to eq 0
31
- ch.close
32
- end
33
- end
34
-
35
- context "with a valid (known) delivery tag (multiple = true)" do
36
- it "acknowledges a message" do
37
- ch = connection.create_channel
38
- q = ch.queue("bunny.basic.ack.manual-acks", exclusive: true)
39
- x = ch.default_exchange
40
-
41
- x.publish("bunneth", routing_key: q.name)
42
- x.publish("bunneth", routing_key: q.name)
43
- sleep 0.5
44
- expect(q.message_count).to eq 2
45
- delivery_details_1, _properties, _content = q.pop(manual_ack: true)
46
- delivery_details_2, _properties, _content = q.pop(manual_ack: true)
47
-
48
- ch.ack(delivery_details_2.delivery_tag, true)
49
- ch.close
50
-
51
- ch = connection.create_channel
52
- q = ch.queue("bunny.basic.ack.manual-acks", exclusive: true)
53
- expect(q.message_count).to eq 0
54
- ch.close
55
- end
56
- end
57
-
58
- context "with a valid (known) delivery tag (multiple = false)" do
59
- it "acknowledges a message" do
60
- ch = connection.create_channel
61
- q = ch.queue("bunny.basic.ack.manual-acks", exclusive: true)
62
- x = ch.default_exchange
63
-
64
- x.publish("bunneth", routing_key: q.name)
65
- x.publish("bunneth", routing_key: q.name)
66
- sleep 0.5
67
- expect(q.message_count).to eq 2
68
- delivery_details_1, _properties, _content = q.pop(manual_ack: true)
69
- delivery_details_2, _properties, _content = q.pop(manual_ack: true)
70
-
71
- ch.ack(delivery_details_2.delivery_tag, false)
72
- ch.close
73
-
74
- ch = connection.create_channel
75
- q = ch.queue("bunny.basic.ack.manual-acks", exclusive: true)
76
- expect(q.message_count).to eq 1
77
- ch.close
78
- end
79
- end
80
-
81
- context "with a valid (known) delivery tag and automatic ack mode" do
82
- it "results in a channel exception" do
83
- ch = connection.create_channel
84
- q = ch.queue("bunny.basic.ack.manual-acks", exclusive: true)
85
- x = ch.default_exchange
86
-
87
- q.subscribe(manual_ack: false) do |delivery_info, properties, payload|
88
- ch.ack(delivery_info.delivery_tag, false)
89
- end
90
-
91
- x.publish("bunneth", routing_key: q.name)
92
- sleep 0.5
93
- expect do
94
- q.message_count
95
- end.to raise_error(Bunny::ChannelAlreadyClosed)
96
- end
97
- end
98
-
99
- context "with an invalid (random) delivery tag" do
100
- it "causes a channel-level error" do
101
- ch = connection.create_channel
102
- q = ch.queue("bunny.basic.ack.unknown-delivery-tag", exclusive: true)
103
- x = ch.default_exchange
104
-
105
- x.publish("bunneth", routing_key: q.name)
106
- sleep 0.5
107
- expect(q.message_count).to eq 1
108
- _, _, content = q.pop(manual_ack: true)
109
-
110
- ch.on_error do |ch, channel_close|
111
- @channel_close = channel_close
112
- end
113
- ch.ack(82, true)
114
- sleep 0.25
115
-
116
- expect(@channel_close.reply_code).to eq AMQ::Protocol::PreconditionFailed::VALUE
117
- end
118
- end
119
-
120
- context "with a valid (known) delivery tag" do
121
- it "gets a depricated message warning for using :ack" do
122
- ch = connection.create_channel
123
- q = ch.queue("bunny.basic.ack.manual-acks", exclusive: true)
124
- x = ch.default_exchange
125
-
126
- x.publish("bunneth", routing_key: q.name)
127
- sleep 0.5
128
- expect(q.message_count).to eq 1
129
-
130
- orig_stderr = $stderr
131
- $stderr = StringIO.new
132
-
133
- delivery_details, properties, content = q.pop(ack: true)
134
-
135
- $stderr.rewind
136
- expect($stderr.string.chomp).to eq("[DEPRECATION] `:ack` is deprecated. Please use `:manual_ack` instead.\n[DEPRECATION] `:ack` is deprecated. Please use `:manual_ack` instead.")
137
-
138
- $stderr = orig_stderr
139
-
140
- ch.ack(delivery_details.delivery_tag, true)
141
- ch.close
142
-
143
- ch = connection.create_channel
144
- q = ch.queue("bunny.basic.ack.manual-acks", exclusive: true)
145
- expect(q.message_count).to eq 0
146
- ch.close
147
- end
148
- end
149
- end
150
-
151
- describe Bunny::Channel, "#basic_ack" do
152
- let(:connection) do
153
- c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
154
- c.start
155
- c
156
- end
157
-
158
- after :each do
159
- connection.close if connection.open?
160
- end
161
-
162
- context "with a valid (known) delivery tag (multiple = true)" do
163
- it "acknowledges a message" do
164
- ch = connection.create_channel
165
- q = ch.queue("bunny.basic.ack.manual-acks", exclusive: true)
166
- x = ch.default_exchange
167
-
168
- x.publish("bunneth", routing_key: q.name)
169
- x.publish("bunneth", routing_key: q.name)
170
- sleep 0.5
171
- expect(q.message_count).to eq 2
172
- delivery_details_1, _properties, _content = q.pop(manual_ack: true)
173
- delivery_details_2, _properties, _content = q.pop(manual_ack: true)
174
-
175
- ch.basic_ack(delivery_details_2.delivery_tag.to_i, true)
176
- ch.close
177
-
178
- ch = connection.create_channel
179
- q = ch.queue("bunny.basic.ack.manual-acks", exclusive: true)
180
- expect(q.message_count).to eq 0
181
- ch.close
182
- end
183
- end
184
-
185
- context "with a valid (known) delivery tag (multiple = false)" do
186
- it "acknowledges a message" do
187
- ch = connection.create_channel
188
- q = ch.queue("bunny.basic.ack.manual-acks", exclusive: true)
189
- x = ch.default_exchange
190
-
191
- x.publish("bunneth", routing_key: q.name)
192
- x.publish("bunneth", routing_key: q.name)
193
- sleep 0.5
194
- expect(q.message_count).to eq 2
195
- delivery_details_1, _properties, _content = q.pop(manual_ack: true)
196
- delivery_details_2, _properties, _content = q.pop(manual_ack: true)
197
-
198
- ch.basic_ack(delivery_details_2.delivery_tag.to_i, false)
199
- ch.close
200
-
201
- ch = connection.create_channel
202
- q = ch.queue("bunny.basic.ack.manual-acks", exclusive: true)
203
- expect(q.message_count).to eq 1
204
- ch.close
205
- end
206
- end
207
-
208
- context "with a valid (known) delivery tag (multiple = default)" do
209
- it "acknowledges a message" do
210
- ch = connection.create_channel
211
- q = ch.queue("bunny.basic.ack.manual-acks", exclusive: true)
212
- x = ch.default_exchange
213
-
214
- x.publish("bunneth", routing_key: q.name)
215
- x.publish("bunneth", routing_key: q.name)
216
- sleep 0.5
217
- expect(q.message_count).to eq 2
218
- delivery_details_1, _properties, _content = q.pop(manual_ack: true)
219
- delivery_details_2, _properties, _content = q.pop(manual_ack: true)
220
-
221
- ch.basic_ack(delivery_details_2.delivery_tag.to_i)
222
- ch.close
223
-
224
- ch = connection.create_channel
225
- q = ch.queue("bunny.basic.ack.manual-acks", exclusive: true)
226
- expect(q.message_count).to eq 1
227
- ch.close
228
- end
229
- end
230
- end
@@ -1,142 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Bunny::Consumer, "#cancel" do
4
- let(:connection) do
5
- c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
6
- c.start
7
- c
8
- end
9
-
10
- after :each do
11
- connection.close if connection.open?
12
- end
13
-
14
- context "with a non-blocking consumer" do
15
- let(:queue_name) { "bunny.queues.#{rand}" }
16
-
17
- it "cancels the consumer" do
18
- delivered_data = []
19
-
20
- t = Thread.new do
21
- ch = connection.create_channel
22
- q = ch.queue(queue_name, auto_delete: true, durable: false)
23
- consumer = q.subscribe do |_, _, payload|
24
- delivered_data << payload
25
- end
26
-
27
- expect(consumer.consumer_tag).not_to be_nil
28
- cancel_ok = consumer.cancel
29
- expect(cancel_ok.consumer_tag).to eq consumer.consumer_tag
30
-
31
- ch.close
32
- end
33
- t.abort_on_exception = true
34
- sleep 0.5
35
-
36
- ch = connection.create_channel
37
- ch.default_exchange.publish("", routing_key: queue_name)
38
-
39
- sleep 0.7
40
- expect(delivered_data).to be_empty
41
- end
42
- end
43
-
44
-
45
- context "with a blocking consumer" do
46
- let(:queue_name) { "bunny.queues.#{rand}" }
47
-
48
- it "cancels the consumer" do
49
- delivered_data = []
50
- consumer = nil
51
-
52
- t = Thread.new do
53
- ch = connection.create_channel
54
- q = ch.queue(queue_name, auto_delete: true, durable: false)
55
-
56
- consumer = Bunny::Consumer.new(ch, q)
57
- consumer.on_delivery do |_, _, payload|
58
- delivered_data << payload
59
- end
60
-
61
- q.subscribe_with(consumer)
62
- end
63
- t.abort_on_exception = true
64
- sleep 1.0
65
-
66
- consumer.cancel
67
- sleep 1.0
68
-
69
- ch = connection.create_channel
70
- ch.default_exchange.publish("", routing_key: queue_name)
71
-
72
- sleep 0.7
73
- expect(delivered_data).to be_empty
74
- end
75
- end
76
-
77
- context "with a worker pool shutdown timeout configured" do
78
- let(:queue_name) { "bunny.queues.#{rand}" }
79
-
80
- it "processes the message if processing completes within the timeout" do
81
- delivered_data = []
82
- consumer = nil
83
-
84
- t = Thread.new do
85
- ch = connection.create_channel(nil, 1, false, 5)
86
- q = ch.queue(queue_name, auto_delete: true, durable: false)
87
-
88
- consumer = Bunny::Consumer.new(ch, q)
89
- consumer.on_delivery do |_, _, payload|
90
- sleep 2
91
- delivered_data << payload
92
- end
93
-
94
- q.subscribe_with(consumer)
95
- end
96
- t.abort_on_exception = true
97
- sleep 1.0
98
-
99
- ch = connection.create_channel
100
- ch.confirm_select
101
- ch.default_exchange.publish("", routing_key: queue_name)
102
- ch.wait_for_confirms
103
- sleep 0.5
104
-
105
- consumer.cancel
106
- sleep 1.0
107
-
108
- expect(delivered_data).to_not be_empty
109
- end
110
-
111
- it "kills the consumer if processing takes longer than the timeout" do
112
- delivered_data = []
113
- consumer = nil
114
-
115
- t = Thread.new do
116
- ch = connection.create_channel(nil, 1, false, 1)
117
- q = ch.queue(queue_name, auto_delete: true, durable: false)
118
-
119
- consumer = Bunny::Consumer.new(ch, q)
120
- consumer.on_delivery do |_, _, payload|
121
- sleep 3
122
- delivered_data << payload
123
- end
124
-
125
- q.subscribe_with(consumer)
126
- end
127
- t.abort_on_exception = true
128
- sleep 1.0
129
-
130
- ch = connection.create_channel
131
- ch.confirm_select
132
- ch.default_exchange.publish("", routing_key: queue_name)
133
- ch.wait_for_confirms
134
- sleep 0.5
135
-
136
- consumer.cancel
137
- sleep 1.0
138
-
139
- expect(delivered_data).to be_empty
140
- end
141
- end
142
- end