def publish(exchange, packet, message, options = {})
      return false unless connected?
      begin
        exchange_options = exchange[:options] || {}
        unless options[:no_serialize]
          log_data = ""
          unless options[:no_log] && logger.level != :debug
            re = "RE-" if packet.respond_to?(:tries) && !packet.tries.empty?
            log_filter = options[:log_filter] unless logger.level == :debug
            log_data = "#{re}SEND #{@alias} #{packet.to_s(log_filter, :send_version)}"
            if logger.level == :debug
              log_data += ", publish options #{options.inspect}, exchange #{exchange[:name]}, " +
                          "type #{exchange[:type]}, options #{exchange[:options].inspect}"
            end
            log_data += ", #{options[:log_data]}" if options[:log_data]
            logger.info(log_data) unless log_data.empty?
          end
        end
        delete_amqp_resources(exchange[:type], exchange[:name]) if exchange_options[:declare]
        @channel.__send__(exchange[:type], exchange[:name], exchange_options).publish(message, options)
        true
      rescue StandardError => e
        logger.exception("Failed publishing to exchange #{exchange.inspect} on broker #{@alias}", e, :trace)
        @exception_stats.track("publish", e)
        update_non_delivery_stats("publish failure", e)
        false
      end
    end
def publish(exchange, packet, message, options = {})
      return false unless connected?
      begin
        exchange_options = exchange[:options] || {}
        unless options[:no_serialize]
          log_data = ""
          unless options[:no_log] && logger.level != :debug
            re = "RE-" if packet.respond_to?(:tries) && !packet.tries.empty?
            log_filter = options[:log_filter] unless logger.level == :debug
            log_data = "#{re}SEND #{@alias} #{packet.to_s(log_filter, :send_version)}"
            if logger.level == :debug
              log_data += ", publish options #{options.inspect}, exchange #{exchange[:name]}, " +
                          "type #{exchange[:type]}, options #{exchange[:options].inspect}"
            end
            log_data += ", #{options[:log_data]}" if options[:log_data]
            logger.info(log_data) unless log_data.empty?
          end
        end
        delete_amqp_resources(exchange[:type], exchange[:name]) if exchange_options[:declare]
        @channel.__send__(exchange[:type], exchange[:name], exchange_options).publish(message, options)
        true
      rescue StandardError => e
        logger.exception("Failed publishing to exchange #{exchange.inspect} on broker #{@alias}", e, :trace)
        @exception_stats.track("publish", e)
        update_non_delivery_stats("publish failure", e)
        false
      end
    end
Publish message to AMQP exchange

 === Parameters
 exchange(Hash):: AMQP exchange to subscribe to with keys :type, :name, and :options,
   which are the standard AMQP ones plus
     :no_declare(Boolean):: Whether to skip declaring this exchange or queue on the broker
       to cause its creation; for use when caller does not have create permission or
       knows the object already exists and wants to avoid declare overhead
     :declare(Boolean):: Whether to delete this exchange or queue from the AMQP cache
       to force it to be declared on the broker and thus be created if it does not exist
 packet(Packet):: Message to serialize and publish (must respond to :to_s(log_filter,
   protocol_version) unless :no_serialize specified; if responds to :type, :from, :token,
   and/or :one_way, these value are used if this message is returned as non-deliverable)
 message(String):: Serialized message to be published
 options(Hash):: Publish options -- standard AMQP ones plus
   :no_serialize(Boolean):: Do not serialize packet because it is already serialized
   :log_filter(Array(Symbol)):: Filters to be applied in to_s when logging packet to :info
   :log_data(String):: Additional data to display at end of log entry
   :no_log(Boolean):: Disable publish logging unless debug level

 === Return
 (Boolean):: true if publish successfully, otherwise false