def connect(host, port, index, priority = nil, force = false)
      @connect_request_stats.update("connect b#{index}")
      even_if = " even if already connected" if force
      Log.info("Connecting to broker at host #{host.inspect} port #{port.inspect} " +
               "index #{index.inspect} priority #{priority.inspect}#{even_if}")
      Log.info("Current broker configuration: #{@client.status.inspect}")
      result = nil
      begin
        @client.connect(host, port, index, priority, force) do |id|
          @client.connection_status(:one_off => @options[:connect_timeout], :brokers => [id]) do |status|
            begin
              if status == :connected
                setup_queues([id])
                remaining = 0
                @remaining_queue_setup.each_value { |ids| remaining += ids.size }
                Log.info("[setup] Finished subscribing to queues after reconnecting to broker #{id}") if remaining == 0
                unless update_configuration(:host => @client.hosts, :port => @client.ports)
                  Log.warning("Successfully connected to broker #{id} but failed to update config file")
                end
              else
                ErrorTracker.log(self, "Failed to connect to broker #{id}, status #{status.inspect}")
              end
            rescue Exception => e
              ErrorTracker.log(self, "Failed to connect to broker #{id}, status #{status.inspect}", e)
            end
          end
        end
      rescue StandardError => e
        ErrorTracker.log(self, msg = "Failed to connect to broker at host #{host.inspect} and port #{port.inspect}", e)
        result = Log.format(msg, e)
      end
      result
    end
def connect(host, port, index, priority = nil, force = false)
      @connect_request_stats.update("connect b#{index}")
      even_if = " even if already connected" if force
      Log.info("Connecting to broker at host #{host.inspect} port #{port.inspect} " +
               "index #{index.inspect} priority #{priority.inspect}#{even_if}")
      Log.info("Current broker configuration: #{@client.status.inspect}")
      result = nil
      begin
        @client.connect(host, port, index, priority, force) do |id|
          @client.connection_status(:one_off => @options[:connect_timeout], :brokers => [id]) do |status|
            begin
              if status == :connected
                setup_queues([id])
                remaining = 0
                @remaining_queue_setup.each_value { |ids| remaining += ids.size }
                Log.info("[setup] Finished subscribing to queues after reconnecting to broker #{id}") if remaining == 0
                unless update_configuration(:host => @client.hosts, :port => @client.ports)
                  Log.warning("Successfully connected to broker #{id} but failed to update config file")
                end
              else
                ErrorTracker.log(self, "Failed to connect to broker #{id}, status #{status.inspect}")
              end
            rescue Exception => e
              ErrorTracker.log(self, "Failed to connect to broker #{id}, status #{status.inspect}", e)
            end
          end
        end
      rescue StandardError => e
        ErrorTracker.log(self, msg = "Failed to connect to broker at host #{host.inspect} and port #{port.inspect}", e)
        result = Log.format(msg, e)
      end
      result
    end
Connect to an additional AMQP broker or reconnect it if connection has failed
 Subscribe to identity queue on this broker
 Update config file if this is a new broker
 Assumes already has credentials on this broker and identity queue exists

 === Parameters
 host(String):: Host name of broker
 port(Integer):: Port number of broker
 index(Integer):: Small unique id associated with this broker for use in forming alias
 priority(Integer|nil):: Priority position of this broker in list for use
   by this agent with nil meaning add to end of list
 force(Boolean):: Reconnect even if already connected

 === Return
 (String|nil):: Error message if failed, otherwise nil