lib/bunny/session.rb in bunny-2.21.0 vs lib/bunny/session.rb in bunny-2.22.0

- old
+ new

@@ -126,10 +126,11 @@ # @option connection_string_or_opts [Boolean] :automatically_recover (true) Should automatically recover from network failures? # @option connection_string_or_opts [Integer] :recovery_attempts (nil) Max number of recovery attempts, nil means forever # @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. # @option connection_string_or_opts [Proc] :recovery_attempt_started (nil) Will be called before every connection recovery attempt # @option connection_string_or_opts [Proc] :recovery_completed (nil) Will be called after successful connection recovery + # @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 # @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)? # @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. # # @option optz [String] :auth_mechanism ("PLAIN") Authentication mechanism, PLAIN or EXTERNAL # @option optz [String] :locale ("PLAIN") Locale RabbitMQ should use @@ -223,10 +224,11 @@ @channels = Hash.new @recovery_attempt_started = opts[:recovery_attempt_started] @recovery_completed = opts[:recovery_completed] + @recovery_attempts_exhausted = opts[:recovery_attempts_exhausted] @session_error_handler = opts.fetch(:session_error_handler, Thread.current) @recoverable_exceptions = DEFAULT_RECOVERABLE_EXCEPTIONS.dup @@ -551,10 +553,16 @@ # after successful connection recovery. def after_recovery_completed(&block) @recovery_completed = block end + # Defines a callable (e.g. a block) that will be called + # when the connection recovery failed after the specified + # numbers of recovery attempts. + def after_recovery_attempts_exhausted(&block) + @recovery_attempts_exhausted = block + end # # Implementation # @@ -807,10 +815,11 @@ else @logger.error "Ran out of recovery attempts (limit set to #{@max_recovery_attempts}), giving up" @transport.close self.close(false) @manually_closed = false + notify_of_recovery_attempts_exhausted end else raise e end end @@ -855,9 +864,14 @@ end # @private def notify_of_recovery_completion @recovery_completed.call if @recovery_completed + end + + # @private + def notify_of_recovery_attempts_exhausted + @recovery_attempts_exhausted.call if @recovery_attempts_exhausted end # @private def instantiate_connection_level_exception(frame) case frame