Components/Queues/QueueManager.php
public function connect(bool $shuffle = true)
    {
        if (!$this->isConnected()) {
            if (empty($this->connections)) {
                throw new \InvalidArgumentException('You have to specify at least one connection.');
            }

            if ($shuffle) {
                shuffle($this->connections);
            }

            $this->connection = null;
            $tested = [];

            foreach ($this->connections as $connection) {
                try {
                    $connection->connect();
                    $this->connection = $connection;
                    break;
                } catch (\AMQPConnectionException $e) {
                    $tested[] = "{$connection->getHost()}: {$e->getMessage()}";
                }
            }

            if (!$this->connection) {
                throw new \RuntimeException(sprintf('Unable to connect to any of the following hosts:%s%s', PHP_EOL, implode(PHP_EOL, $tested)));
            }

            //Create and declare channel
            $this->channel = new \AMQPChannel($this->connection);
            $this->channel->setPrefetchCount(1);

            //AMQPC Exchange is the publishing mechanism
            $this->exchange = new \AMQPExchange($this->channel);
        }
    }
public function connect(bool $shuffle = true)
    {
        if (!$this->isConnected()) {
            if (empty($this->connections)) {
                throw new \InvalidArgumentException('You have to specify at least one connection.');
            }

            if ($shuffle) {
                shuffle($this->connections);
            }

            $this->connection = null;
            $tested = [];

            foreach ($this->connections as $connection) {
                try {
                    $connection->connect();
                    $this->connection = $connection;
                    break;
                } catch (\AMQPConnectionException $e) {
                    $tested[] = "{$connection->getHost()}: {$e->getMessage()}";
                }
            }

            if (!$this->connection) {
                throw new \RuntimeException(sprintf('Unable to connect to any of the following hosts:%s%s', PHP_EOL, implode(PHP_EOL, $tested)));
            }

            //Create and declare channel
            $this->channel = new \AMQPChannel($this->connection);
            $this->channel->setPrefetchCount(1);

            //AMQPC Exchange is the publishing mechanism
            $this->exchange = new \AMQPExchange($this->channel);
        }
    }
public function connect ( bool $ shuffle = true ) { if ( ! $ this -> isConnected ( ) ) { if ( empty ( $ this -> connections ) ) { throw new \ InvalidArgumentException ( 'You have to specify at least one connection.' ) ; } if ( $ shuffle ) { shuffle ( $ this -> connections ) ; } $ this -> connection = null ; $ tested = [ ] ; foreach ( $ this -> connections as $ connection ) { try { $ connection -> connect ( ) ; $ this -> connection = $ connection ; break ; } catch ( \ AMQPConnectionException $ e ) { $ tested [ ] = "{$connection->getHost()}: {$e->getMessage()}" ; } } if ( ! $ this -> connection ) { throw new \ RuntimeException ( sprintf ( 'Unable to connect to any of the following hosts:%s%s' , PHP_EOL , implode ( PHP_EOL , $ tested ) ) ) ; } //Create and declare channel $ this -> channel = new \ AMQPChannel ( $ this -> connection ) ; $ this -> channel -> setPrefetchCount ( 1 ) ; //AMQPC Exchange is the publishing mechanism $ this -> exchange = new \ AMQPExchange ( $ this -> channel ) ; } }
Opens a connection with a queuing system.

@param bool $shuffle Shuffle connections to avoid connecting to the seame endpoint everytime

@throws \AMQPException
Opens a connection with a queuing system .