bunny 2.20.3 → 2.22.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0638b435d0f724c5b9566797df9ba50e94144f0bb82f60b01e5d794bce868512'
4
- data.tar.gz: c278e7122a90653738ff68b845509873ed0e7ca7b5759e0a33a7157725bcf650
3
+ metadata.gz: 2edd88411f92dbdbb1d06b334006e446d5b3e3fb165f3baae3745bd066cf9651
4
+ data.tar.gz: 437032f606bb6f77fee02e65706e615f8a52c0e05467bbe257f1796fcedd624c
5
5
  SHA512:
6
- metadata.gz: 44e1c56c0500d2e375a22e6349401e25d9e1c8f9e553b91df0ed4ac07ee80167cd50e28f6191e549961a31c7795e07a740949b72c971178b2f35060a221cc312
7
- data.tar.gz: c0cbd8f1d0d6b6973f6ba6e3cc6140dbaa6843fe18cb00372e5b3a01bbdad5f1c265867b8314937ed711671266fb14fb281bbf739b2510a91fad4404b6ba4042
6
+ metadata.gz: 698398dc76ca4e3dd11e3c5dc6b078998f23895bd3d975b01e1329c08c8ff0835cb9691d0108f0f6e13aaa769b870b258ff5e1de1958321be4804ca99b30a0be
7
+ data.tar.gz: 2a1fdcc61d683a991d07f601a986c5bc04d40cdd7155a1833dc7dba46be014c23d36612c505531b2f2adfe08ed057d6a493cbf5df368318205ffaf88659a88fb
data/lib/bunny/channel.rb CHANGED
@@ -378,7 +378,7 @@ module Bunny
378
378
  # @see http://rubybunny.info/articles/exchanges.html Exchanges and Publishing guide
379
379
  # @api public
380
380
  def default_exchange
381
- Exchange.default(self)
381
+ @default_exchange ||= Exchange.default(self)
382
382
  end
383
383
 
384
384
  # Declares a headers exchange or looks it up in the cache of previously
@@ -396,7 +396,7 @@ module Bunny
396
396
  # @see http://rubybunny.info/articles/exchanges.html Exchanges and Publishing guide
397
397
  # @see http://rubybunny.info/articles/extensions.html RabbitMQ Extensions to AMQP 0.9.1 guide
398
398
  def exchange(name, opts = {})
399
- Exchange.new(self, opts.fetch(:type, :direct), name, opts)
399
+ find_exchange(name) || Exchange.new(self, opts.fetch(:type, :direct), name, opts)
400
400
  end
401
401
 
402
402
  # @endgroup
@@ -70,7 +70,7 @@ module Bunny
70
70
  return if !(wait_for_workers && @shutdown_timeout && was_running)
71
71
 
72
72
  @shutdown_mutex.synchronize do
73
- @shutdown_conditional.wait(@shutdown_mutex, @shutdown_timeout)
73
+ @shutdown_conditional.wait(@shutdown_mutex, @shutdown_timeout) if busy?
74
74
  end
75
75
  end
76
76
 
data/lib/bunny/session.rb CHANGED
@@ -71,6 +71,7 @@ module Bunny
71
71
  # Default reconnection interval for TCP connection failures
72
72
  DEFAULT_NETWORK_RECOVERY_INTERVAL = 5.0
73
73
 
74
+ DEFAULT_RECOVERABLE_EXCEPTIONS = [StandardError, TCPConnectionFailedForAllHosts, TCPConnectionFailed, AMQ::Protocol::EmptyResponseError, SystemCallError, Timeout::Error, Bunny::ConnectionLevelException, Bunny::ConnectionClosedError]
74
75
 
75
76
  #
76
77
  # API
@@ -91,6 +92,7 @@ module Bunny
91
92
  attr_reader :network_recovery_interval
92
93
  attr_reader :connection_name
93
94
  attr_accessor :socket_configurator
95
+ attr_accessor :recoverable_exceptions
94
96
 
95
97
  # @param [String, Hash] connection_string_or_opts Connection string or a hash of connection options
96
98
  # @param [Hash] optz Extra options not related to connection
@@ -126,6 +128,7 @@ module Bunny
126
128
  # @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
129
  # @option connection_string_or_opts [Proc] :recovery_attempt_started (nil) Will be called before every connection recovery attempt
128
130
  # @option connection_string_or_opts [Proc] :recovery_completed (nil) Will be called after successful connection recovery
131
+ # @option connection_string_or_opts [Proc] :recovery_attempts_exhausted (nil) Will be called when the connection recovery failed after the specified amount of recovery attempts
129
132
  # @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
133
  # @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.
131
134
  #
@@ -223,9 +226,12 @@ module Bunny
223
226
 
224
227
  @recovery_attempt_started = opts[:recovery_attempt_started]
225
228
  @recovery_completed = opts[:recovery_completed]
229
+ @recovery_attempts_exhausted = opts[:recovery_attempts_exhausted]
226
230
 
227
231
  @session_error_handler = opts.fetch(:session_error_handler, Thread.current)
228
232
 
233
+ @recoverable_exceptions = DEFAULT_RECOVERABLE_EXCEPTIONS.dup
234
+
229
235
  self.reset_continuations
230
236
  self.initialize_transport
231
237
 
@@ -549,6 +555,12 @@ module Bunny
549
555
  @recovery_completed = block
550
556
  end
551
557
 
558
+ # Defines a callable (e.g. a block) that will be called
559
+ # when the connection recovery failed after the specified
560
+ # numbers of recovery attempts.
561
+ def after_recovery_attempts_exhausted(&block)
562
+ @recovery_attempts_exhausted = block
563
+ end
552
564
 
553
565
  #
554
566
  # Implementation
@@ -747,9 +759,7 @@ module Bunny
747
759
 
748
760
  # @private
749
761
  def recoverable_network_failure?(exception)
750
- # No reasonably smart strategy was suggested in a few years.
751
- # So just recover unconditionally. MK.
752
- true
762
+ @recoverable_exceptions.any? {|x| exception.kind_of? x}
753
763
  end
754
764
 
755
765
  # @private
@@ -794,19 +804,23 @@ module Bunny
794
804
  rescue HostListDepleted
795
805
  reset_address_index
796
806
  retry
797
- rescue TCPConnectionFailedForAllHosts, TCPConnectionFailed, AMQ::Protocol::EmptyResponseError, SystemCallError, Timeout::Error => e
798
- @logger.warn "TCP connection failed, reconnecting in #{@network_recovery_interval} seconds"
799
- if should_retry_recovery?
800
- decrement_recovery_attemp_counter!
801
- if recoverable_network_failure?(e)
807
+ rescue => e
808
+ if recoverable_network_failure?(e)
809
+ @logger.warn "TCP connection failed"
810
+ if should_retry_recovery?
811
+ @logger.warn "Reconnecting in #{@network_recovery_interval} seconds"
812
+ decrement_recovery_attemp_counter!
802
813
  announce_network_failure_recovery
803
814
  retry
815
+ else
816
+ @logger.error "Ran out of recovery attempts (limit set to #{@max_recovery_attempts}), giving up"
817
+ @transport.close
818
+ self.close(false)
819
+ @manually_closed = false
820
+ notify_of_recovery_attempts_exhausted
804
821
  end
805
822
  else
806
- @logger.error "Ran out of recovery attempts (limit set to #{@max_recovery_attempts}), giving up"
807
- @transport.close
808
- self.close(false)
809
- @manually_closed = false
823
+ raise e
810
824
  end
811
825
  end
812
826
 
@@ -854,6 +868,11 @@ module Bunny
854
868
  @recovery_completed.call if @recovery_completed
855
869
  end
856
870
 
871
+ # @private
872
+ def notify_of_recovery_attempts_exhausted
873
+ @recovery_attempts_exhausted.call if @recovery_attempts_exhausted
874
+ end
875
+
857
876
  # @private
858
877
  def instantiate_connection_level_exception(frame)
859
878
  case frame
@@ -1356,7 +1375,7 @@ module Bunny
1356
1375
  host_from_address(address),
1357
1376
  port_from_address(address),
1358
1377
  @opts.merge(:session_error_handler => @session_error_handler)
1359
- )
1378
+ )
1360
1379
 
1361
1380
  # Reset the cached progname for the logger only when no logger was provided
1362
1381
  @default_logger.progname = self.to_s
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.20.3"
5
+ VERSION = "2.22.0"
6
6
  end
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.20.3
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: 2023-01-26 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
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  requirements: []
123
- rubygems_version: 3.1.4
123
+ rubygems_version: 3.5.0.dev
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: Popular easy to use Ruby client for RabbitMQ