bunny 2.14.4 → 2.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +30 -12
  3. data/lib/bunny/channel.rb +2 -2
  4. data/lib/bunny/queue.rb +0 -3
  5. data/lib/bunny/reader_loop.rb +11 -11
  6. data/lib/bunny/session.rb +42 -9
  7. data/lib/bunny/transport.rb +12 -11
  8. data/lib/bunny/version.rb +1 -1
  9. data/spec/higher_level_api/integration/basic_cancel_spec.rb +4 -4
  10. data/spec/higher_level_api/integration/basic_consume_spec.rb +17 -9
  11. data/spec/higher_level_api/integration/connection_spec.rb +26 -0
  12. data/spec/higher_level_api/integration/tls_connection_spec.rb +194 -189
  13. data/spec/issues/issue202_spec.rb +1 -1
  14. data/spec/issues/issue609_spec.rb +84 -0
  15. data/spec/issues/issue78_spec.rb +2 -2
  16. data/spec/lower_level_api/integration/basic_cancel_spec.rb +1 -1
  17. data/spec/lower_level_api/integration/basic_consume_spec.rb +8 -8
  18. data/spec/unit/exchange_recovery_spec.rb +2 -2
  19. metadata +37 -95
  20. data/.github/ISSUE_TEMPLATE.md +0 -18
  21. data/.gitignore +0 -28
  22. data/.rspec +0 -1
  23. data/.travis.yml +0 -32
  24. data/.yardopts +0 -8
  25. data/CONTRIBUTING.md +0 -132
  26. data/ChangeLog.md +0 -2103
  27. data/Gemfile +0 -55
  28. data/LICENSE +0 -21
  29. data/Rakefile +0 -54
  30. data/benchmarks/basic_publish/with_128K_messages.rb +0 -35
  31. data/benchmarks/basic_publish/with_1k_messages.rb +0 -35
  32. data/benchmarks/basic_publish/with_4K_messages.rb +0 -35
  33. data/benchmarks/basic_publish/with_64K_messages.rb +0 -35
  34. data/benchmarks/channel_open.rb +0 -28
  35. data/benchmarks/mutex_and_monitor.rb +0 -42
  36. data/benchmarks/queue_declare.rb +0 -29
  37. data/benchmarks/queue_declare_and_bind.rb +0 -29
  38. data/benchmarks/queue_declare_bind_and_delete.rb +0 -29
  39. data/benchmarks/synchronized_sorted_set.rb +0 -53
  40. data/benchmarks/write_vs_write_nonblock.rb +0 -49
  41. data/bunny.gemspec +0 -34
  42. data/docker-compose.yml +0 -28
  43. data/docker/Dockerfile +0 -24
  44. data/docker/apt/preferences.d/erlang +0 -3
  45. data/docker/apt/sources.list.d/bintray.rabbitmq.list +0 -2
  46. data/docker/docker-entrypoint.sh +0 -26
  47. data/docker/rabbitmq.conf +0 -29
  48. data/examples/connection/authentication_failure.rb +0 -16
  49. data/examples/connection/automatic_recovery_with_basic_get.rb +0 -40
  50. data/examples/connection/automatic_recovery_with_client_named_queues.rb +0 -36
  51. data/examples/connection/automatic_recovery_with_multiple_consumers.rb +0 -46
  52. data/examples/connection/automatic_recovery_with_republishing.rb +0 -109
  53. data/examples/connection/automatic_recovery_with_server_named_queues.rb +0 -35
  54. data/examples/connection/channel_level_exception.rb +0 -27
  55. data/examples/connection/disabled_automatic_recovery.rb +0 -34
  56. data/examples/connection/heartbeat.rb +0 -17
  57. data/examples/connection/manually_reconnecting_consumer.rb +0 -23
  58. data/examples/connection/manually_reconnecting_publisher.rb +0 -28
  59. data/examples/connection/unknown_host.rb +0 -16
  60. data/examples/consumers/high_and_low_priority.rb +0 -50
  61. data/examples/guides/exchanges/direct_exchange_routing.rb +0 -36
  62. data/examples/guides/exchanges/fanout_exchange_routing.rb +0 -28
  63. data/examples/guides/exchanges/headers_exchange_routing.rb +0 -31
  64. data/examples/guides/exchanges/mandatory_messages.rb +0 -30
  65. data/examples/guides/extensions/alternate_exchange.rb +0 -30
  66. data/examples/guides/extensions/basic_nack.rb +0 -33
  67. data/examples/guides/extensions/connection_blocked.rb +0 -35
  68. data/examples/guides/extensions/consumer_cancellation_notification.rb +0 -39
  69. data/examples/guides/extensions/dead_letter_exchange.rb +0 -32
  70. data/examples/guides/extensions/exchange_to_exchange_bindings.rb +0 -29
  71. data/examples/guides/extensions/per_message_ttl.rb +0 -36
  72. data/examples/guides/extensions/per_queue_message_ttl.rb +0 -36
  73. data/examples/guides/extensions/publisher_confirms.rb +0 -28
  74. data/examples/guides/extensions/queue_lease.rb +0 -26
  75. data/examples/guides/extensions/sender_selected_distribution.rb +0 -32
  76. data/examples/guides/getting_started/blabbr.rb +0 -27
  77. data/examples/guides/getting_started/hello_world.rb +0 -22
  78. data/examples/guides/getting_started/weathr.rb +0 -49
  79. data/examples/guides/queues/one_off_consumer.rb +0 -25
  80. data/examples/guides/queues/redeliveries.rb +0 -81
  81. data/profiling/basic_publish/with_4K_messages.rb +0 -33
  82. data/repl +0 -3
  83. data/spec/tls/generate-server-cert.sh +0 -8
  84. data/spec/tls/server-openssl.cnf +0 -10
  85. data/spec/tls/server.csr +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf0bcb6bc92f6092788f0eeffed76f438be49f1341857a6e5a94254544cf44e3
4
- data.tar.gz: 317240a20f888087e959999b7cbe10d57fe423316032bc6fa6f2a6733e8dd50c
3
+ metadata.gz: d6de535f1d386dbf46fd89a733c1c44915280af55c3cc3cc56467abe0ead9c24
4
+ data.tar.gz: 6048aea84078fb8995718ed774d9a3956dc91645b24c09382cd54283b444aabe
5
5
  SHA512:
6
- metadata.gz: d0c159c08871fdf203a322543489d9c563d45c855f407f9e069adc6f3f0d97f7b0fb8d7ac90a5280dfdc2cea81dbef53e0c2b217be2064373432d0ca0d889626
7
- data.tar.gz: 4d8a071b4d8494ad3976d842a705cf3d8323d8c14c61a0c147c309cc07ebc77bf6420243a597c68a3cde9b4b7a6cb5f17e25bab7972cf607f1d1d55b8bd88cdb
6
+ metadata.gz: b3575710f81dabf6c116c92c4ac1807a29f0c0bcd1bd5fb35ae1fd9dd468df193efac49d0ad5e77ef04ecc53e97b9b4e13e70f4207972ba0c2335c28afcd6c9b
7
+ data.tar.gz: 8b90dd4da7dab28b529e78cf1282656ca1904432b1017ee5574545c1972315f975d175c718481372604b61796e9ae56b293a342dcba800fa0929e4b80cd7a3c4
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.3 through 2.6 (inclusive)
50
+ * CRuby 2.5 through 3.0 (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,8 @@ 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.18.x](https://github.com/ruby-amqp/bunny/blob/2.18.x-stable/ChangeLog.md)
74
+ * [2.17.x](https://github.com/ruby-amqp/bunny/blob/2.17.x-stable/ChangeLog.md)
78
75
 
79
76
 
80
77
 
@@ -97,7 +94,7 @@ gem install bunny
97
94
  To use Bunny in a project managed with Bundler:
98
95
 
99
96
  ``` ruby
100
- gem "bunny", ">= 2.13.0"
97
+ gem "bunny", ">= 2.18.0"
101
98
  ```
102
99
 
103
100
 
@@ -117,20 +114,31 @@ conn.start
117
114
 
118
115
  # open a channel
119
116
  ch = conn.create_channel
117
+ ch.confirm_select
120
118
 
121
119
  # declare a queue
122
120
  q = ch.queue("test1")
121
+ q.subscribe(manual_ack: true) do |delivery_info, metadata, payload|
122
+ puts "This is the message: #{payload}"
123
+ # acknowledge the delivery so that RabbitMQ can mark it for deletion
124
+ ch.ack(delivery_info.delivery_tag)
125
+ end
123
126
 
124
127
  # publish a message to the default exchange which then gets routed to this queue
125
128
  q.publish("Hello, everybody!")
126
129
 
127
- # fetch a message from the queue
128
- delivery_info, metadata, payload = q.pop
130
+ # await confirmations from RabbitMQ, see
131
+ # https://www.rabbitmq.com/publishers.html#data-safety for details
132
+ ch.wait_for_confirms
133
+
134
+ # give the above consumer some time consume the delivery and print out the message
135
+ sleep 1
129
136
 
130
- puts "This is the message: #{payload}"
137
+ puts "Done"
131
138
 
139
+ ch.close
132
140
  # close the connection
133
- conn.stop
141
+ conn.close
134
142
  ```
135
143
 
136
144
 
@@ -142,7 +150,7 @@ For a 15 minute tutorial using more practical examples, see [Getting Started wit
142
150
 
143
151
  ### Guides
144
152
 
145
- Other documentation guides are available at [rubybunny.info](http://rubybunny.info):
153
+ Bunny documentation guides are available at [rubybunny.info](http://rubybunny.info):
146
154
 
147
155
  * [Queues and Consumers](http://rubybunny.info/articles/queues.html)
148
156
  * [Exchanges and Publishers](http://rubybunny.info/articles/exchanges.html)
@@ -154,6 +162,16 @@ Other documentation guides are available at [rubybunny.info](http://rubybunny.in
154
162
  * [Using RabbitMQ Extensions with Bunny](http://rubybunny.info/articles/extensions.html)
155
163
  * [Durability and Related Matters](http://rubybunny.info/articles/durability.html)
156
164
 
165
+ Some highly relevant RabbitMQ documentation guides:
166
+
167
+ * [Connections](https://www.rabbitmq.com/connections.html)
168
+ * [Channels](https://www.rabbitmq.com/channels.html)
169
+ * [Queues](https://www.rabbitmq.com/queues.html)
170
+ * [Publishers](https://www.rabbitmq.com/publishers.html)
171
+ * [Consumers](https://www.rabbitmq.com/consumers.html)
172
+ * Data safety: publisher and consumer [Confirmations](https://www.rabbitmq.com/confirms.html)
173
+ * [Production Checklist](https://www.rabbitmq.com/production-checklist.html)
174
+
157
175
  ### API Reference
158
176
 
159
177
  [Bunny API Reference](http://reference.rubybunny.info/).
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.
@@ -1789,7 +1789,7 @@ module Bunny
1789
1789
  # @private
1790
1790
  def handle_ack_or_nack(delivery_tag_before_offset, multiple, nack)
1791
1791
  delivery_tag = delivery_tag_before_offset + @delivery_tag_offset
1792
- confirmed_range_start = multiple ? @delivery_tag_offset + 1 : delivery_tag
1792
+ confirmed_range_start = multiple ? @delivery_tag_offset + @unconfirmed_set.min : delivery_tag
1793
1793
  confirmed_range_end = delivery_tag
1794
1794
  confirmed_range = (confirmed_range_start..confirmed_range_end)
1795
1795
 
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?
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,7 +174,7 @@ 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
174
179
  @recovering_from_network_failure = false
175
180
  @max_recovery_attempts = opts[:recovery_attempts]
@@ -197,7 +202,9 @@ module Bunny
197
202
  @client_heartbeat = self.heartbeat_from(opts)
198
203
 
199
204
  client_props = opts[:properties] || opts[:client_properties] || {}
205
+ @connection_name = client_props[:connection_name] || opts[:connection_name]
200
206
  @client_properties = DEFAULT_CLIENT_PROPERTIES.merge(client_props)
207
+ .merge(connection_name: connection_name)
201
208
  @mechanism = normalize_auth_mechanism(opts.fetch(:auth_mechanism, "PLAIN"))
202
209
  @credentials_encoder = credentials_encoder_for(@mechanism)
203
210
  @locale = @opts.fetch(:locale, DEFAULT_LOCALE)
@@ -213,9 +220,11 @@ module Bunny
213
220
  @address_index_mutex = @mutex_impl.new
214
221
 
215
222
  @channels = Hash.new
216
- @recovery_completed = opts[:recovery_completed]
217
223
 
218
- @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)
219
228
 
220
229
  self.reset_continuations
221
230
  self.initialize_transport
@@ -342,6 +351,14 @@ module Bunny
342
351
  self
343
352
  end
344
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
+
345
362
  # Socket operation write timeout used by this connection
346
363
  # @return [Integer]
347
364
  # @private
@@ -520,6 +537,18 @@ module Bunny
520
537
  end
521
538
  end
522
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
+
523
552
 
524
553
  #
525
554
  # Implementation
@@ -632,6 +661,8 @@ module Bunny
632
661
  when AMQ::Protocol::Connection::Unblocked then
633
662
  @blocked = false
634
663
  @unblock_callback.call(method) if @unblock_callback
664
+ when AMQ::Protocol::Connection::UpdateSecretOk then
665
+ @continuations.push(method)
635
666
  when AMQ::Protocol::Channel::Close then
636
667
  begin
637
668
  ch = synchronised_find_channel(ch_number)
@@ -735,6 +766,7 @@ module Bunny
735
766
  def recover_from_network_failure
736
767
  sleep @network_recovery_interval
737
768
  @logger.debug "Will attempt connection recovery..."
769
+ notify_of_recovery_attempt_start
738
770
 
739
771
  self.initialize_transport
740
772
 
@@ -808,8 +840,9 @@ module Bunny
808
840
  end
809
841
  end
810
842
 
811
- def after_recovery_completed(&block)
812
- @recovery_completed = block
843
+ # @private
844
+ def notify_of_recovery_attempt_start
845
+ @recovery_attempt_started.call if @recovery_attempt_started
813
846
  end
814
847
 
815
848
  # @private
@@ -852,7 +885,7 @@ module Bunny
852
885
 
853
886
  clean_up_on_shutdown
854
887
  if threaded?
855
- @origin_thread.raise(@last_connection_error)
888
+ @session_error_handler.raise(@last_connection_error)
856
889
  else
857
890
  raise @last_connection_error
858
891
  end
@@ -1009,7 +1042,7 @@ module Bunny
1009
1042
 
1010
1043
  # @private
1011
1044
  def reader_loop
1012
- @reader_loop ||= ReaderLoop.new(@transport, self, Thread.current)
1045
+ @reader_loop ||= ReaderLoop.new(@transport, self, @session_error_handler)
1013
1046
  end
1014
1047
 
1015
1048
  # @private
@@ -1272,7 +1305,7 @@ module Bunny
1272
1305
  end
1273
1306
 
1274
1307
  if threaded?
1275
- @origin_thread.raise(e)
1308
+ @session_error_handler.raise(e)
1276
1309
  else
1277
1310
  raise e
1278
1311
  end
@@ -1318,7 +1351,7 @@ module Bunny
1318
1351
  @transport = Transport.new(self,
1319
1352
  host_from_address(address),
1320
1353
  port_from_address(address),
1321
- @opts.merge(:session_thread => @origin_thread)
1354
+ @opts.merge(:session_error_handler => @session_error_handler)
1322
1355
  )
1323
1356
 
1324
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.4"
5
+ VERSION = "2.19.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