setVhost() public method

Sets the virtual host to which to connect on the AMQP broker.
public setVhost ( string $vhost ) : boolean
$vhost string The virtual host to use on the AMQP broker.
return boolean true on success or false on failure.
示例#1
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (empty($this->user)) {
         throw new \Exception("Parameter 'user' was not set for AMQP connection.");
     }
     if (empty(self::$ampqConnection)) {
         self::$ampqConnection = new \AMQPConnection();
         self::$ampqConnection->setHost($this->host);
         self::$ampqConnection->setPort($this->port);
         self::$ampqConnection->setLogin($this->user);
         self::$ampqConnection->setPassword($this->password);
         self::$ampqConnection->setVhost($this->vhost);
         self::$ampqConnection->connect();
     }
 }
示例#2
0
 /**
  * Returns AMQP connection
  *
  * @return AMQPConnection
  */
 public function connection()
 {
     if (!$this->connection) {
         if (!$this->host || !$this->port) {
             throw new \InvalidArgumentException(sprintf("Remote host or port undefined '%s:%s' ", $this->host, $this->port));
         }
         $this->connection = new \AMQPConnection();
         $this->connection->setHost($this->host);
         $this->connection->setPort($this->port);
         $this->connection->setLogin($this->user);
         $this->connection->setPassword($this->password);
         $this->vhost and $this->connection->setVhost($this->vhost);
         $this->connection->connect();
     }
     return $this->connection;
 }
示例#3
0
 /**
  * @inheritdoc
  */
 public function setVhost($vhost)
 {
     try {
         return $this->delegate->setVhost($vhost);
     } catch (\AMQPConnectionException $e) {
         throw new ConnectionException($e->getMessage(), $e->getCode(), $e);
     }
 }
示例#4
0
 /**
  * Return AMQPConnection object passed to all other calls
  * @param array $details Array of connection details
  * @return AMQPConnection
  */
 function GetConnectionObject($details)
 {
     $connection = new AMQPConnection();
     $connection->setHost($details['host']);
     $connection->setLogin($details['login']);
     $connection->setPassword($details['password']);
     $connection->setVhost($details['vhost']);
     $connection->setPort($details['port']);
     return $connection;
 }
示例#5
0
 static function InitializeAMQPConnection($details)
 {
     $connection = new AMQPConnection();
     $connection->setHost($details['host']);
     $connection->setLogin($details['login']);
     $connection->setPassword($details['password']);
     $connection->setVhost($details['vhost']);
     $connection->setPort($details['port']);
     return $connection;
 }
 protected function createAMQPConnection()
 {
     $connection = new AMQPConnection();
     $connection->setHost($this->getHost());
     $connection->setPort($this->getPort());
     $connection->setVhost($this->getVhost());
     $connection->setLogin($this->getLogin());
     $connection->setPassword($this->getPassword());
     $connection->connect();
     return $connection;
 }
示例#7
0
 function getBrokerStatus()
 {
     $amqpConnection = new AMQPConnection();
     $amqpConnection->setLogin("guest");
     $amqpConnection->setPassword("guest");
     $amqpConnection->setVhost("/");
     $amqpConnection->connect();
     if (!$amqpConnection->isConnected()) {
         log("info", "Cannot connect to the broker!");
         return false;
     }
     $amqpConnection->disconnect();
     return true;
 }
示例#8
0
 /**
  * Connects to the broken
  *
  * @return CakeAmqpBase
  * @throws CakeException 
  */
 public function connect()
 {
     if ($this->connected()) {
         throw new CakeException(__d('cake_amqp', 'Already connected to broker'));
     }
     $this->_connection = new AMQPConnection();
     $this->_connection->setHost($this->_config['host']);
     $this->_connection->setPort($this->_config['port']);
     $this->_connection->setLogin($this->_config['user']);
     $this->_connection->setPassword($this->_config['pass']);
     $this->_connection->setVhost($this->_config['vhost']);
     $this->_connection->connect();
     $this->_channel = new AMQPChannel($this->_connection);
     return $this;
 }
 private function checkRabbitMQ()
 {
     $amqpConnection = new AMQPConnection();
     $amqpConnection->setHost($this->mqHost);
     $amqpConnection->setLogin($this->mqUser);
     $amqpConnection->setPassword($this->mqPass);
     $amqpConnection->setVhost($this->mqVhost);
     $amqpConnection->setPort($this->mqPort);
     $amqpConnection->connect();
     return $amqpConnection->isConnected();
 }
示例#10
0
<?php

echo "<pre>";
//$conn_args = array("host"=>'localhost','port'=>5672,'login'=>'guest',"password"=>'guest','vhost'=>'/');
//$conn = new AMQPConnection($conn_args);
$conn = new AMQPConnection();
$conn->setLogin("guest");
$conn->setPassword("guest");
$conn->setPort(5672);
$conn->setVhost("/");
if ($conn->connect()) {
    echo "Success\r\n";
} else {
    echo "Fail\r\n";
}
var_dump($conn);
 /**
  * @param string $host
  * @param int $port
  * @param string $vhost
  * @param string $login
  * @param string $password
  * @param float $connectionTimeout
  * @return AMQPConnection
  * @throws AMQPConnectionException
  * @throws Exception
  */
 protected function createAMQPConnection($host, $port, $vhost, $login, $password, $connectionTimeout)
 {
     $connection = new AMQPConnection();
     $connection->setHost($host);
     $connection->setPort($port);
     $connection->setVhost($vhost);
     $connection->setLogin($login);
     $connection->setPassword($password);
     $connection->setReadTimeout($connectionTimeout);
     if (!$connection->connect()) {
         throw new Exception('Cannot connect to the broker');
     }
     return $connection;
 }