bunny 2.14.3 → 2.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -7
  3. data/lib/bunny/channel.rb +1 -1
  4. data/lib/bunny/cruby/socket.rb +3 -0
  5. data/lib/bunny/queue.rb +0 -3
  6. data/lib/bunny/reader_loop.rb +19 -12
  7. data/lib/bunny/session.rb +44 -9
  8. data/lib/bunny/transport.rb +12 -11
  9. data/lib/bunny/version.rb +1 -1
  10. data/spec/higher_level_api/integration/basic_cancel_spec.rb +4 -4
  11. data/spec/higher_level_api/integration/basic_consume_spec.rb +17 -9
  12. data/spec/higher_level_api/integration/connection_spec.rb +26 -0
  13. data/spec/higher_level_api/integration/tls_connection_spec.rb +194 -189
  14. data/spec/issues/issue202_spec.rb +1 -1
  15. data/spec/issues/issue609_spec.rb +84 -0
  16. data/spec/issues/issue78_spec.rb +2 -2
  17. data/spec/lower_level_api/integration/basic_cancel_spec.rb +1 -1
  18. data/spec/lower_level_api/integration/basic_consume_spec.rb +8 -8
  19. data/spec/unit/exchange_recovery_spec.rb +2 -2
  20. metadata +37 -95
  21. data/.github/ISSUE_TEMPLATE.md +0 -18
  22. data/.gitignore +0 -28
  23. data/.rspec +0 -1
  24. data/.travis.yml +0 -31
  25. data/.yardopts +0 -8
  26. data/CONTRIBUTING.md +0 -132
  27. data/ChangeLog.md +0 -2084
  28. data/Gemfile +0 -55
  29. data/LICENSE +0 -21
  30. data/Rakefile +0 -54
  31. data/benchmarks/basic_publish/with_128K_messages.rb +0 -35
  32. data/benchmarks/basic_publish/with_1k_messages.rb +0 -35
  33. data/benchmarks/basic_publish/with_4K_messages.rb +0 -35
  34. data/benchmarks/basic_publish/with_64K_messages.rb +0 -35
  35. data/benchmarks/channel_open.rb +0 -28
  36. data/benchmarks/mutex_and_monitor.rb +0 -42
  37. data/benchmarks/queue_declare.rb +0 -29
  38. data/benchmarks/queue_declare_and_bind.rb +0 -29
  39. data/benchmarks/queue_declare_bind_and_delete.rb +0 -29
  40. data/benchmarks/synchronized_sorted_set.rb +0 -53
  41. data/benchmarks/write_vs_write_nonblock.rb +0 -49
  42. data/bunny.gemspec +0 -34
  43. data/docker-compose.yml +0 -28
  44. data/docker/Dockerfile +0 -24
  45. data/docker/apt/preferences.d/erlang +0 -3
  46. data/docker/apt/sources.list.d/bintray.rabbitmq.list +0 -2
  47. data/docker/docker-entrypoint.sh +0 -26
  48. data/docker/rabbitmq.conf +0 -29
  49. data/examples/connection/authentication_failure.rb +0 -16
  50. data/examples/connection/automatic_recovery_with_basic_get.rb +0 -40
  51. data/examples/connection/automatic_recovery_with_client_named_queues.rb +0 -36
  52. data/examples/connection/automatic_recovery_with_multiple_consumers.rb +0 -46
  53. data/examples/connection/automatic_recovery_with_republishing.rb +0 -109
  54. data/examples/connection/automatic_recovery_with_server_named_queues.rb +0 -35
  55. data/examples/connection/channel_level_exception.rb +0 -27
  56. data/examples/connection/disabled_automatic_recovery.rb +0 -34
  57. data/examples/connection/heartbeat.rb +0 -17
  58. data/examples/connection/manually_reconnecting_consumer.rb +0 -23
  59. data/examples/connection/manually_reconnecting_publisher.rb +0 -28
  60. data/examples/connection/unknown_host.rb +0 -16
  61. data/examples/consumers/high_and_low_priority.rb +0 -50
  62. data/examples/guides/exchanges/direct_exchange_routing.rb +0 -36
  63. data/examples/guides/exchanges/fanout_exchange_routing.rb +0 -28
  64. data/examples/guides/exchanges/headers_exchange_routing.rb +0 -31
  65. data/examples/guides/exchanges/mandatory_messages.rb +0 -30
  66. data/examples/guides/extensions/alternate_exchange.rb +0 -30
  67. data/examples/guides/extensions/basic_nack.rb +0 -33
  68. data/examples/guides/extensions/connection_blocked.rb +0 -35
  69. data/examples/guides/extensions/consumer_cancellation_notification.rb +0 -39
  70. data/examples/guides/extensions/dead_letter_exchange.rb +0 -32
  71. data/examples/guides/extensions/exchange_to_exchange_bindings.rb +0 -29
  72. data/examples/guides/extensions/per_message_ttl.rb +0 -36
  73. data/examples/guides/extensions/per_queue_message_ttl.rb +0 -36
  74. data/examples/guides/extensions/publisher_confirms.rb +0 -28
  75. data/examples/guides/extensions/queue_lease.rb +0 -26
  76. data/examples/guides/extensions/sender_selected_distribution.rb +0 -32
  77. data/examples/guides/getting_started/blabbr.rb +0 -27
  78. data/examples/guides/getting_started/hello_world.rb +0 -22
  79. data/examples/guides/getting_started/weathr.rb +0 -49
  80. data/examples/guides/queues/one_off_consumer.rb +0 -25
  81. data/examples/guides/queues/redeliveries.rb +0 -81
  82. data/profiling/basic_publish/with_4K_messages.rb +0 -33
  83. data/repl +0 -3
  84. data/spec/tls/generate-server-cert.sh +0 -8
  85. data/spec/tls/server-openssl.cnf +0 -10
  86. data/spec/tls/server.csr +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c29f135d76d09fb4260a945a620a80d281b5194ea55bdd9e4fd1f43b9e849544
4
- data.tar.gz: 23ff6197091a0d373fbad760dba33ec199bbacd85d274f4a828afd8d78b2d28c
3
+ metadata.gz: 12c06caafbcd9f9246ab4bd8431fd4eaea5dbbd312ff0d44a771eba7ed6a9a45
4
+ data.tar.gz: 73aa41037c3c38ff236ddec494cbb9b7678804265e1ec90c8fca0a6bafcdff8f
5
5
  SHA512:
6
- metadata.gz: 4c73f2103a2c7ab9df2ae497592e37c5d28c2e92ff2e8833337375859aa7eb08082952cf1314762df9fe3599b4fb958050ea4242d13c8cf4283ce0cf4bfa0315
7
- data.tar.gz: 3ab49bec79e0bbacd7e06d3e9d84b0dbb3a3dac0c3cbbf131a96b51c1c6c5fdd50b2cc85d94a5f8bbc9440f6a4a976cdc6e3669d1c1ccf49639f976156cafb50
6
+ metadata.gz: 8abbfee40480a6421fb1b17004796970cfec645ec133d9330ae7338b0877ee8f8ef8a2eda8ccce00106fccef0c73d009da1179345261509d6f30de300df38db3
7
+ data.tar.gz: 62748d088e8b346041f502f02ef08837b78ecf0acc5e2599c5e7640c6f6af7fcba4dfa261b7cc1e458bf672fe69ecc423660905c7f220bfb1b933937ea2537ea
data/README.md CHANGED
@@ -43,12 +43,11 @@ Specific examples:
43
43
  Web applications that display that information in the real time.
44
44
 
45
45
 
46
-
47
46
  ## Supported Ruby Versions
48
47
 
49
48
  Modern Bunny versions support
50
49
 
51
- * CRuby 2.2 through 2.5 (inclusive)
50
+ * CRuby 2.3 through 2.7 (inclusive)
52
51
 
53
52
  Bunny works sufficiently well on JRuby but there are known
54
53
  JRuby bugs in versions prior to JRuby 9000 that cause high CPU burn. JRuby users should
@@ -71,10 +70,10 @@ a stable public API.
71
70
  Change logs per release series:
72
71
 
73
72
  * [master](https://github.com/ruby-amqp/bunny/blob/master/ChangeLog.md)
74
- * [2.13.x](https://github.com/ruby-amqp/bunny/blob/2.13.x-stable/ChangeLog.md)
75
- * [2.12.x](https://github.com/ruby-amqp/bunny/blob/2.12.x-stable/ChangeLog.md)
76
- * [2.11.x](https://github.com/ruby-amqp/bunny/blob/2.11.x-stable/ChangeLog.md)
77
- * [2.10.x](https://github.com/ruby-amqp/bunny/blob/2.10.x-stable/ChangeLog.md)
73
+ * [2.17.x](https://github.com/ruby-amqp/bunny/blob/2.17.x-stable/ChangeLog.md)
74
+ * [2.16.x](https://github.com/ruby-amqp/bunny/blob/2.16.x-stable/ChangeLog.md)
75
+ * [2.15.x](https://github.com/ruby-amqp/bunny/blob/2.15.x-stable/ChangeLog.md)
76
+ * [2.14.x](https://github.com/ruby-amqp/bunny/blob/2.14.x-stable/ChangeLog.md)
78
77
 
79
78
 
80
79
 
@@ -97,7 +96,7 @@ gem install bunny
97
96
  To use Bunny in a project managed with Bundler:
98
97
 
99
98
  ``` ruby
100
- gem "bunny", ">= 2.13.0"
99
+ gem "bunny", ">= 2.17.0"
101
100
  ```
102
101
 
103
102
 
data/lib/bunny/channel.rb CHANGED
@@ -1156,7 +1156,7 @@ module Bunny
1156
1156
 
1157
1157
  # @group Exchange operations (exchange.*)
1158
1158
 
1159
- # Declares a exchange using echange.declare AMQP 0.9.1 method.
1159
+ # Declares a exchange using exchange.declare AMQP 0.9.1 method.
1160
1160
  #
1161
1161
  # @param [String] name The name of the exchange. Note that LF and CR characters
1162
1162
  # will be stripped from the value.
@@ -32,6 +32,9 @@ module Bunny
32
32
  socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, true)
33
33
  end
34
34
  socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_KEEPALIVE, true) if options.fetch(:keepalive, true)
35
+ socket.instance_eval do
36
+ @__bunny_socket_eof_flag__ = false
37
+ end
35
38
  socket.extend self
36
39
  socket.options = { :host => host, :port => port }.merge(options)
37
40
  socket
data/lib/bunny/queue.rb CHANGED
@@ -158,9 +158,6 @@ module Bunny
158
158
  # @option opts [Boolean] :ack (false) [DEPRECATED] Use :manual_ack instead
159
159
  # @option opts [Boolean] :manual_ack (false) Will this consumer use manual acknowledgements?
160
160
  # @option opts [Boolean] :exclusive (false) Should this consumer be exclusive for this queue?
161
- # @option opts [Boolean] :block (false) Should the call block the calling thread? This option can be useful for keeping the main thread of
162
- # a script alive. It is incompatible with automatic connection recovery
163
- # and is not generally recommended.
164
161
  # @option opts [#call] :on_cancellation Block to execute when this consumer is cancelled remotely (e.g. via the RabbitMQ Management plugin)
165
162
  # @option opts [String] :consumer_tag Unique consumer identifier. It is usually recommended to let Bunny generate it for you.
166
163
  # @option opts [Hash] :arguments ({}) Additional (optional) arguments, typically used by RabbitMQ extensions
@@ -9,17 +9,17 @@ module Bunny
9
9
  # @private
10
10
  class ReaderLoop
11
11
 
12
- def initialize(transport, session, session_thread)
13
- @transport = transport
14
- @session = session
15
- @session_thread = session_thread
16
- @logger = @session.logger
12
+ def initialize(transport, session, session_error_handler)
13
+ @transport = transport
14
+ @session = session
15
+ @session_error_handler = session_error_handler
16
+ @logger = @session.logger
17
17
 
18
- @mutex = Mutex.new
18
+ @mutex = Mutex.new
19
19
 
20
- @stopping = false
21
- @stopped = false
22
- @network_is_down = false
20
+ @stopping = false
21
+ @stopped = false
22
+ @network_is_down = false
23
23
  end
24
24
 
25
25
 
@@ -47,7 +47,7 @@ module Bunny
47
47
  @session.handle_network_failure(e)
48
48
  else
49
49
  log_exception(e)
50
- @session_thread.raise(Bunny::NetworkFailure.new("detected a network failure: #{e.message}", e))
50
+ @session_error_handler.raise(Bunny::NetworkFailure.new("detected a network failure: #{e.message}", e))
51
51
  end
52
52
  rescue ShutdownSignal => _
53
53
  @mutex.synchronize { @stopping = true }
@@ -58,7 +58,7 @@ module Bunny
58
58
  log_exception(e)
59
59
 
60
60
  @network_is_down = true
61
- @session_thread.raise(Bunny::NetworkFailure.new("caught an unexpected exception in the network loop: #{e.message}", e))
61
+ @session_error_handler.raise(Bunny::NetworkFailure.new("caught an unexpected exception in the network loop: #{e.message}", e))
62
62
  end
63
63
  rescue Errno::EBADF => _ebadf
64
64
  break if terminate?
@@ -116,7 +116,14 @@ module Bunny
116
116
  end
117
117
 
118
118
  def join
119
- @thread.join if @thread
119
+ # Thread#join can/would trigger a re-raise of an unhandled exception in this thread.
120
+ # In addition, Thread.handle_interrupt can be used by other libraries or application code
121
+ # that would make this join operation fail with an obscure exception.
122
+ # So we try to save everyone some really unpleasant debugging time by introducing
123
+ # this condition which typically would not evaluate to true anyway.
124
+ #
125
+ # See ruby-amqp/bunny#589 and ruby-amqp/bunny#590 for background.
126
+ @thread.join if @thread && @thread != Thread.current
120
127
  end
121
128
 
122
129
  def kill
data/lib/bunny/session.rb CHANGED
@@ -89,6 +89,7 @@ module Bunny
89
89
  # @return [Integer] Timeout for blocking protocol operations (queue.declare, queue.bind, etc), in milliseconds. Default is 15000.
90
90
  attr_reader :continuation_timeout
91
91
  attr_reader :network_recovery_interval
92
+ attr_reader :connection_name
92
93
  attr_accessor :socket_configurator
93
94
 
94
95
  # @param [String, Hash] connection_string_or_opts Connection string or a hash of connection options
@@ -123,10 +124,14 @@ module Bunny
123
124
  # @option connection_string_or_opts [Boolean] :automatically_recover (true) Should automatically recover from network failures?
124
125
  # @option connection_string_or_opts [Integer] :recovery_attempts (nil) Max number of recovery attempts, nil means forever
125
126
  # @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.
127
+ # @option connection_string_or_opts [Proc] :recovery_attempt_started (nil) Will be called before every connection recovery attempt
128
+ # @option connection_string_or_opts [Proc] :recovery_completed (nil) Will be called after successful connection recovery
126
129
  # @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)?
130
+ # @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.
127
131
  #
128
132
  # @option optz [String] :auth_mechanism ("PLAIN") Authentication mechanism, PLAIN or EXTERNAL
129
133
  # @option optz [String] :locale ("PLAIN") Locale RabbitMQ should use
134
+ # @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.
130
135
  #
131
136
  # @see http://rubybunny.info/articles/connecting.html Connecting to RabbitMQ guide
132
137
  # @see http://rubybunny.info/articles/tls.html TLS/SSL guide
@@ -169,8 +174,9 @@ module Bunny
169
174
  @automatically_recover = if opts[:automatically_recover].nil? && opts[:automatic_recovery].nil?
170
175
  true
171
176
  else
172
- opts[:automatically_recover] || opts[:automatic_recovery]
177
+ opts[:automatically_recover] | opts[:automatic_recovery]
173
178
  end
179
+ @recovering_from_network_failure = false
174
180
  @max_recovery_attempts = opts[:recovery_attempts]
175
181
  @recovery_attempts = @max_recovery_attempts
176
182
  # When this is set, connection attempts won't be reset after
@@ -184,6 +190,7 @@ module Bunny
184
190
  @continuation_timeout = opts.fetch(:continuation_timeout, DEFAULT_CONTINUATION_TIMEOUT)
185
191
 
186
192
  @status = :not_connected
193
+ @manually_closed = false
187
194
  @blocked = false
188
195
 
189
196
  # these are negotiated with the broker during the connection tuning phase
@@ -195,7 +202,9 @@ module Bunny
195
202
  @client_heartbeat = self.heartbeat_from(opts)
196
203
 
197
204
  client_props = opts[:properties] || opts[:client_properties] || {}
205
+ @connection_name = client_props[:connection_name] || opts[:connection_name]
198
206
  @client_properties = DEFAULT_CLIENT_PROPERTIES.merge(client_props)
207
+ .merge(connection_name: connection_name)
199
208
  @mechanism = normalize_auth_mechanism(opts.fetch(:auth_mechanism, "PLAIN"))
200
209
  @credentials_encoder = credentials_encoder_for(@mechanism)
201
210
  @locale = @opts.fetch(:locale, DEFAULT_LOCALE)
@@ -211,9 +220,11 @@ module Bunny
211
220
  @address_index_mutex = @mutex_impl.new
212
221
 
213
222
  @channels = Hash.new
214
- @recovery_completed = opts[:recovery_completed]
215
223
 
216
- @origin_thread = Thread.current
224
+ @recovery_attempt_started = opts[:recovery_attempt_started]
225
+ @recovery_completed = opts[:recovery_completed]
226
+
227
+ @session_error_handler = opts.fetch(:session_error_handler, Thread.current)
217
228
 
218
229
  self.reset_continuations
219
230
  self.initialize_transport
@@ -340,6 +351,14 @@ module Bunny
340
351
  self
341
352
  end
342
353
 
354
+ def update_secret(value, reason)
355
+ @transport.send_frame(AMQ::Protocol::Connection::UpdateSecret.encode(value, reason))
356
+ @last_update_secret_ok = wait_on_continuations
357
+ raise_if_continuation_resulted_in_a_connection_error!
358
+
359
+ @last_update_secret_ok
360
+ end
361
+
343
362
  # Socket operation write timeout used by this connection
344
363
  # @return [Integer]
345
364
  # @private
@@ -518,6 +537,18 @@ module Bunny
518
537
  end
519
538
  end
520
539
 
540
+ # Defines a callable (e.g. a block) that will be called
541
+ # before every connection recovery attempt.
542
+ def before_recovery_attempt_starts(&block)
543
+ @recovery_attempt_started = block
544
+ end
545
+
546
+ # Defines a callable (e.g. a block) that will be called
547
+ # after successful connection recovery.
548
+ def after_recovery_completed(&block)
549
+ @recovery_completed = block
550
+ end
551
+
521
552
 
522
553
  #
523
554
  # Implementation
@@ -630,6 +661,8 @@ module Bunny
630
661
  when AMQ::Protocol::Connection::Unblocked then
631
662
  @blocked = false
632
663
  @unblock_callback.call(method) if @unblock_callback
664
+ when AMQ::Protocol::Connection::UpdateSecretOk then
665
+ @continuations.push(method)
633
666
  when AMQ::Protocol::Channel::Close then
634
667
  begin
635
668
  ch = synchronised_find_channel(ch_number)
@@ -733,6 +766,7 @@ module Bunny
733
766
  def recover_from_network_failure
734
767
  sleep @network_recovery_interval
735
768
  @logger.debug "Will attempt connection recovery..."
769
+ notify_of_recovery_attempt_start
736
770
 
737
771
  self.initialize_transport
738
772
 
@@ -806,8 +840,9 @@ module Bunny
806
840
  end
807
841
  end
808
842
 
809
- def after_recovery_completed(&block)
810
- @recovery_completed = block
843
+ # @private
844
+ def notify_of_recovery_attempt_start
845
+ @recovery_attempt_started.call if @recovery_attempt_started
811
846
  end
812
847
 
813
848
  # @private
@@ -850,7 +885,7 @@ module Bunny
850
885
 
851
886
  clean_up_on_shutdown
852
887
  if threaded?
853
- @origin_thread.raise(@last_connection_error)
888
+ @session_error_handler.raise(@last_connection_error)
854
889
  else
855
890
  raise @last_connection_error
856
891
  end
@@ -1007,7 +1042,7 @@ module Bunny
1007
1042
 
1008
1043
  # @private
1009
1044
  def reader_loop
1010
- @reader_loop ||= ReaderLoop.new(@transport, self, Thread.current)
1045
+ @reader_loop ||= ReaderLoop.new(@transport, self, @session_error_handler)
1011
1046
  end
1012
1047
 
1013
1048
  # @private
@@ -1270,7 +1305,7 @@ module Bunny
1270
1305
  end
1271
1306
 
1272
1307
  if threaded?
1273
- @origin_thread.raise(e)
1308
+ @session_error_handler.raise(e)
1274
1309
  else
1275
1310
  raise e
1276
1311
  end
@@ -1316,7 +1351,7 @@ module Bunny
1316
1351
  @transport = Transport.new(self,
1317
1352
  host_from_address(address),
1318
1353
  port_from_address(address),
1319
- @opts.merge(:session_thread => @origin_thread)
1354
+ @opts.merge(:session_error_handler => @session_error_handler)
1320
1355
  )
1321
1356
 
1322
1357
  # Reset the cached progname for the logger only when no logger was provided
@@ -35,7 +35,7 @@ module Bunny
35
35
 
36
36
  def initialize(session, host, port, opts)
37
37
  @session = session
38
- @session_thread = opts[:session_thread]
38
+ @session_error_handler = opts[:session_error_handler]
39
39
  @host = host
40
40
  @port = port
41
41
  @opts = opts
@@ -146,7 +146,7 @@ module Bunny
146
146
  if @session.automatically_recover?
147
147
  @session.handle_network_failure(e)
148
148
  else
149
- @session_thread.raise(Bunny::NetworkFailure.new("detected a network failure: #{e.message}", e))
149
+ @session_error_handler.raise(Bunny::NetworkFailure.new("detected a network failure: #{e.message}", e))
150
150
  end
151
151
  end
152
152
  end
@@ -170,7 +170,7 @@ module Bunny
170
170
  if @session.automatically_recover?
171
171
  @session.handle_network_failure(e)
172
172
  else
173
- @session_thread.raise(Bunny::NetworkFailure.new("detected a network failure: #{e.message}", e))
173
+ @session_error_handler.raise(Bunny::NetworkFailure.new("detected a network failure: #{e.message}", e))
174
174
  end
175
175
  end
176
176
  end
@@ -188,7 +188,7 @@ module Bunny
188
188
  if @session.automatically_recover?
189
189
  @session.handle_network_failure(e)
190
190
  else
191
- @session_thread.raise(Bunny::NetworkFailure.new("detected a network failure: #{e.message}", e))
191
+ @session_error_handler.raise(Bunny::NetworkFailure.new("detected a network failure: #{e.message}", e))
192
192
  end
193
193
  end
194
194
  end
@@ -245,7 +245,7 @@ module Bunny
245
245
  if @session.automatically_recover?
246
246
  raise
247
247
  else
248
- @session_thread.raise(Bunny::NetworkFailure.new("detected a network failure: #{e.message}", e))
248
+ @session_error_handler.raise(Bunny::NetworkFailure.new("detected a network failure: #{e.message}", e))
249
249
  end
250
250
  end
251
251
  end
@@ -453,9 +453,9 @@ module Bunny
453
453
  end
454
454
  end
455
455
 
456
- def initialize_tls_context(ctx, opts={})
456
+ def initialize_tls_context(ctx, opts = {})
457
457
  ctx.cert = OpenSSL::X509::Certificate.new(@tls_certificate) if @tls_certificate
458
- ctx.key = OpenSSL::PKey::RSA.new(@tls_key) if @tls_key
458
+ ctx.key = OpenSSL::PKey.read(@tls_key) if @tls_key
459
459
  ctx.cert_store = if @tls_certificate_store
460
460
  @tls_certificate_store
461
461
  else
@@ -463,8 +463,9 @@ module Bunny
463
463
  @tls_ca_certificates = tls_ca_certificates_paths_from(opts)
464
464
  initialize_tls_certificate_store(@tls_ca_certificates)
465
465
  end
466
+ should_silence_warnings = opts.fetch(:tls_silence_warnings, false)
466
467
 
467
- if !@tls_certificate
468
+ if !@tls_certificate && !should_silence_warnings
468
469
  @logger.warn <<-MSG
469
470
  Using TLS but no client certificate is provided. If RabbitMQ is configured to require & verify peer
470
471
  certificate, connection will be rejected. Learn more at https://www.rabbitmq.com/ssl.html
@@ -482,14 +483,14 @@ certificate, connection will be rejected. Learn more at https://www.rabbitmq.com
482
483
  @logger.debug { "Will use peer verification mode #{verify_mode}" }
483
484
  ctx.verify_mode = verify_mode
484
485
 
485
- if !@verify_peer
486
+ if !@verify_peer && !should_silence_warnings
486
487
  @logger.warn <<-MSG
487
488
  Using TLS but peer hostname verification is disabled. This is convenient for local development
488
489
  but prone to man-in-the-middle attacks. Please set verify_peer: true in production. Learn more at https://www.rabbitmq.com/ssl.html
489
490
  MSG
490
491
  end
491
492
 
492
- ssl_version = opts[:tls_protocol] || opts[:ssl_version]
493
+ ssl_version = opts[:tls_protocol] || opts[:ssl_version] || :TLSv1_2
493
494
  ctx.ssl_version = ssl_version if ssl_version
494
495
 
495
496
  ctx
@@ -501,7 +502,7 @@ but prone to man-in-the-middle attacks. Please set verify_peer: true in producti
501
502
  certs.each do |cert|
502
503
  # if it starts with / or C:/ then it's a file path that may or may not
503
504
  # exist (e.g. a default OpenSSL path). MK.
504
- if File.readable?(cert) || cert =~ /^([a-z]:?)?\//i
505
+ if File.readable?(cert) || cert =~ /\A([a-z]:?)?\//i
505
506
  cert_files.push(cert)
506
507
  else
507
508
  cert_inlines.push(cert)
data/lib/bunny/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Bunny
4
4
  # @return [String] Version of the library
5
- VERSION = "2.14.3"
5
+ VERSION = "2.18.0"
6
6
  end
@@ -20,7 +20,7 @@ describe Bunny::Consumer, "#cancel" do
20
20
  t = Thread.new do
21
21
  ch = connection.create_channel
22
22
  q = ch.queue(queue_name, auto_delete: true, durable: false)
23
- consumer = q.subscribe(block: false) do |_, _, payload|
23
+ consumer = q.subscribe do |_, _, payload|
24
24
  delivered_data << payload
25
25
  end
26
26
 
@@ -58,7 +58,7 @@ describe Bunny::Consumer, "#cancel" do
58
58
  delivered_data << payload
59
59
  end
60
60
 
61
- q.subscribe_with(consumer, block: false)
61
+ q.subscribe_with(consumer)
62
62
  end
63
63
  t.abort_on_exception = true
64
64
  sleep 1.0
@@ -91,7 +91,7 @@ describe Bunny::Consumer, "#cancel" do
91
91
  delivered_data << payload
92
92
  end
93
93
 
94
- q.subscribe_with(consumer, block: false)
94
+ q.subscribe_with(consumer)
95
95
  end
96
96
  t.abort_on_exception = true
97
97
  sleep 1.0
@@ -122,7 +122,7 @@ describe Bunny::Consumer, "#cancel" do
122
122
  delivered_data << payload
123
123
  end
124
124
 
125
- q.subscribe_with(consumer, block: false)
125
+ q.subscribe_with(consumer)
126
126
  end
127
127
  t.abort_on_exception = true
128
128
  sleep 1.0
@@ -62,8 +62,10 @@ describe Bunny::Queue, "#subscribe" do
62
62
  x.publish("hello", routing_key: queue_name)
63
63
  end
64
64
 
65
- sleep 1.0
66
- expect(delivery_tags).to eq SortedSet.new(Range.new(1, 100).to_a)
65
+ sleep 1.5
66
+ 100.times do |i|
67
+ expect(delivery_tags).to include(i + 1)
68
+ end
67
69
 
68
70
  expect(ch.queue(queue_name, auto_delete: true, durable: false).message_count).to eq 0
69
71
 
@@ -95,7 +97,9 @@ describe Bunny::Queue, "#subscribe" do
95
97
  end
96
98
 
97
99
  sleep 1.5
98
- expect(delivery_tags).to eq SortedSet.new(Range.new(1, 100).to_a)
100
+ 100.times do |i|
101
+ expect(delivery_tags).to include(i + 1)
102
+ end
99
103
 
100
104
  expect(ch.queue(queue_name, auto_delete: true, durable: false).message_count).to eq 0
101
105
 
@@ -189,17 +193,17 @@ describe Bunny::Queue, "#subscribe" do
189
193
  ch = connection.create_channel
190
194
  q = ch.queue(queue_name)
191
195
 
192
- c1 = q.subscribe(exclusive: false, manual_ack: false, block: false) do |delivery_info, properties, payload|
196
+ c1 = q.subscribe(exclusive: false, manual_ack: false) do |delivery_info, properties, payload|
193
197
  end
194
198
  c1.cancel
195
199
 
196
- c2 = q.subscribe(exclusive: false, manual_ack: false, block: false) do |delivery_info, properties, payload|
200
+ c2 = q.subscribe(exclusive: false, manual_ack: false) do |delivery_info, properties, payload|
197
201
  delivered_keys << delivery_info.routing_key
198
202
  delivered_data << payload
199
203
  end
200
204
  c2.cancel
201
205
 
202
- q.subscribe(exclusive: false, manual_ack: false, block: true) do |delivery_info, properties, payload|
206
+ q.subscribe(exclusive: false, manual_ack: false) do |delivery_info, properties, payload|
203
207
  delivered_keys << delivery_info.routing_key
204
208
  delivered_data << payload
205
209
  end
@@ -305,8 +309,10 @@ describe Bunny::Queue, "#subscribe" do
305
309
  x.publish("hello", routing_key: queue_name)
306
310
  end
307
311
 
308
- sleep 1.0
309
- expect(delivery_tags).to eq SortedSet.new(Range.new(1, 100).to_a)
312
+ sleep 1.5
313
+ 100.times do |i|
314
+ expect(delivery_tags).to include(i + 1)
315
+ end
310
316
 
311
317
  expect(ch.queue(queue_name, auto_delete: true, durable: false).message_count).to eq 0
312
318
 
@@ -338,7 +344,9 @@ describe Bunny::Queue, "#subscribe" do
338
344
  end
339
345
 
340
346
  sleep 1.5
341
- expect(delivery_tags).to eq SortedSet.new(Range.new(1, 100).to_a)
347
+ 100.times do |i|
348
+ expect(delivery_tags).to include(i + 1)
349
+ end
342
350
 
343
351
  expect(ch.queue(queue_name, auto_delete: true, durable: false).message_count).to eq 0
344
352