def handle_return(identity, to, reason, message)
      @brokers_hash[identity].update_status(:stopping) if reason == "ACCESS_REFUSED"

      if context = @published.fetch(message)
        @return_stats.update("#{alias_(identity)} (#{reason.to_s.downcase})")
        context.record_failure(identity)
        name = context.name
        options = context.options || {}
        token = context.token
        one_way = context.one_way
        persistent = options[:persistent]
        mandatory = true
        remaining = (context.brokers - context.failed) & connected
        logger.info("RETURN reason #{reason} token <#{token}> to #{to} from #{context.from} brokers #{context.brokers.inspect} " +
                    "failed #{context.failed.inspect} remaining #{remaining.inspect} connected #{connected.inspect}")
        if remaining.empty?
          if (persistent || one_way) &&
             ["ACCESS_REFUSED", "NO_CONSUMERS"].include?(reason) &&
             !(remaining = context.brokers & connected).empty?
            # Retry because persistent, and this time w/o mandatory so that gets queued even though no consumers
            mandatory = false
          else
            t = token ? " <#{token}>" : ""
            logger.info("NO ROUTE #{aliases(context.brokers).join(", ")} [#{name}]#{t} to #{to}")
            @non_delivery.call(reason, context.type, token, context.from, to) if @non_delivery
            @non_delivery_stats.update("no route")
          end
        end

        unless remaining.empty?
          t = token ? " <#{token}>" : ""
          p = persistent ? ", persistent" : ""
          m = mandatory ? ", mandatory" : ""
          logger.info("RE-ROUTE #{aliases(remaining).join(", ")} [#{context.name}]#{t} to #{to}#{p}#{m}")
          exchange = {:type => :queue, :name => to, :options => {:no_declare => true}}
          publish(exchange, message, options.merge(:no_serialize => true, :brokers => remaining,
                                                   :persistent => persistent, :mandatory => mandatory))
        end
      else
        @return_stats.update("#{alias_(identity)} (#{reason.to_s.downcase} - missing context)")
        logger.info("Dropping message returned from broker #{identity} for reason #{reason} " +
                    "because no message context available for re-routing it to #{to}")
      end
      true
    rescue Exception => e
      logger.exception("Failed to handle #{reason} return from #{identity} for message being routed to #{to}", e, :trace)
      @exception_stats.track("return", e)
    end
def handle_return(identity, to, reason, message)
      @brokers_hash[identity].update_status(:stopping) if reason == "ACCESS_REFUSED"

      if context = @published.fetch(message)
        @return_stats.update("#{alias_(identity)} (#{reason.to_s.downcase})")
        context.record_failure(identity)
        name = context.name
        options = context.options || {}
        token = context.token
        one_way = context.one_way
        persistent = options[:persistent]
        mandatory = true
        remaining = (context.brokers - context.failed) & connected
        logger.info("RETURN reason #{reason} token <#{token}> to #{to} from #{context.from} brokers #{context.brokers.inspect} " +
                    "failed #{context.failed.inspect} remaining #{remaining.inspect} connected #{connected.inspect}")
        if remaining.empty?
          if (persistent || one_way) &&
             ["ACCESS_REFUSED", "NO_CONSUMERS"].include?(reason) &&
             !(remaining = context.brokers & connected).empty?
            # Retry because persistent, and this time w/o mandatory so that gets queued even though no consumers
            mandatory = false
          else
            t = token ? " <#{token}>" : ""
            logger.info("NO ROUTE #{aliases(context.brokers).join(", ")} [#{name}]#{t} to #{to}")
            @non_delivery.call(reason, context.type, token, context.from, to) if @non_delivery
            @non_delivery_stats.update("no route")
          end
        end

        unless remaining.empty?
          t = token ? " <#{token}>" : ""
          p = persistent ? ", persistent" : ""
          m = mandatory ? ", mandatory" : ""
          logger.info("RE-ROUTE #{aliases(remaining).join(", ")} [#{context.name}]#{t} to #{to}#{p}#{m}")
          exchange = {:type => :queue, :name => to, :options => {:no_declare => true}}
          publish(exchange, message, options.merge(:no_serialize => true, :brokers => remaining,
                                                   :persistent => persistent, :mandatory => mandatory))
        end
      else
        @return_stats.update("#{alias_(identity)} (#{reason.to_s.downcase} - missing context)")
        logger.info("Dropping message returned from broker #{identity} for reason #{reason} " +
                    "because no message context available for re-routing it to #{to}")
      end
      true
    rescue Exception => e
      logger.exception("Failed to handle #{reason} return from #{identity} for message being routed to #{to}", e, :trace)
      @exception_stats.track("return", e)
    end
Handle message returned by broker because it could not deliver it
 If agent still active, resend using another broker
 If this is last usable broker and persistent is enabled, allow message to be queued
 on next send even if the queue has no consumers so there is a chance of message
 eventually being delivered
 If persistent or one-way request and all usable brokers have failed, try one more time
 without mandatory flag to give message opportunity to be queued
 If there are no more usable broker clients, send non-delivery message to original sender

 === Parameters
 identity(String):: Identity of broker that could not deliver message
 to(String):: Queue to which message was published
 reason(String):: Reason for return
   "NO_ROUTE" - queue does not exist
   "NO_CONSUMERS" - queue exists but it has no consumers, or if :immediate was specified,
     all consumers are not immediately ready to consume
   "ACCESS_REFUSED" - queue not usable because broker is in the process of stopping service
 message(String):: Returned message in serialized packet format

 === Return
 true:: Always return true