lib/wookie/handlers.rb
# Helper logic for retry handling. This will reject the message if there
# are remaining retries left on it, otherwise it will publish it to the
# error exchange along with the reason.
# @param delivery_info [Bunny::DeliveryInfo]
# @param metadata [Bunny::MessageProperties]
# @param payload [String] The message
# @param reason [String, Symbol, Exception] Reason for the retry, included
#   in the JSON we put on the error exchange.
Helper logic for retry handling. This will reject the message if there
are remaining retries left on it, otherwise it will publish it to the
error exchange along with the reason.
Helper logic for retry handling . This will reject the message if there are remaining retries left on it otherwise it will publish it to the error exchange along with the reason .
def handle_retry(payload, delivery_info, metadata, reason)
      num_attempts = failure_count(metadata[:headers]) + 1
      if num_attempts <= @max_retries
        @channel.reject(delivery_info.delivery_tag, false)
      else
        data = {
          error: reason,
          num_attempts: num_attempts,
          failed_at: Time.now.iso8601,
          payload: Base64.encode64(payload.to_s)
        }.tap do |hash|
          if reason.is_a?(Exception)
            hash[:error_class] = reason.class
            hash[:error_message] = "#{reason}"
            if reason.backtrace
              hash[:backtrace] = reason.backtrace.take(10).join(', ')
            end
          end
        end.to_json
        @error_exchange.publish(data, :routing_key => delivery_info.routing_key)
        @channel.acknowledge(delivery_info.delivery_tag, false)
      end
    end
def handle_retry ( payload , delivery_info , metadata , reason ) num_attempts = failure_count ( metadata [ :headers ] ) + 1 if num_attempts <= @max_retries @channel . reject ( delivery_info . delivery_tag , false ) else data = { error : reason , num_attempts : num_attempts , failed_at : Time . now . iso8601 , payload : Base64 . encode64 ( payload . to_s ) } . tap do | hash | if reason . is_a? ( Exception ) hash [ :error_class ] = reason . class hash [ :error_message ] = "#{reason}" if reason . backtrace hash [ :backtrace ] = reason . backtrace . take ( 10 ) . join ( ', ' ) end end end . to_json @error_exchange . publish ( data , :routing_key => delivery_info . routing_key ) @channel . acknowledge ( delivery_info . delivery_tag , false ) end end
Helper logic for retry handling.
Helper logic for retry handling .
# +1 for the current attempt # We call reject which will route the message to the # x-dead-letter-exchange (ie. retry exchange) on the queue # TODO: metrics # Retried more than the max times # Publish the original message with the routing_key to the error exchange # TODO: metrics
payload
None
delivery_info
metadata
reason
Reason for the retry, included in the JSON we put on the error exchange.
Reason for the retry included in the JSON we put on the error exchange .
None