示例#1
0
 /**
  * @param PhpAmqpLib_Connection_AbstractConnection $connection
  * @param null $channel_id
  * @param bool $auto_decode
  * @throws Exception
  */
 public function __construct($connection, $channel_id = null, $auto_decode = true)
 {
     if ($channel_id == null) {
         $channel_id = $connection->get_free_channel_id();
     }
     parent::__construct($connection, $channel_id);
     $this->publish_cache = array();
     $this->publish_cache_max_size = 100;
     if ($this->debug) {
         PhpAmqpLib_Helper_MiscHelper::debug_msg('using channel_id: ' . $channel_id);
     }
     $this->default_ticket = 0;
     $this->is_open = false;
     $this->active = true;
     // Flow control
     $this->alerts = array();
     $this->callbacks = array();
     $this->auto_decode = $auto_decode;
     try {
         $this->x_open();
     } catch (Exception $e) {
         $this->close();
         throw $e;
     }
 }
示例#2
0
 public function __construct($connection, $channel_id = null, $auto_decode = true)
 {
     if ($channel_id == null) {
         $channel_id = $connection->get_free_channel_id();
     }
     parent::__construct($connection, $channel_id);
     if ($this->debug) {
         PhpAmqpLib_Helper_MiscHelper::debug_msg("using channel_id: " . $channel_id);
     }
     $this->default_ticket = 0;
     $this->is_open = false;
     $this->active = true;
     // Flow control
     $this->alerts = array();
     $this->callbacks = array();
     $this->auto_decode = $auto_decode;
     $this->x_open();
 }
 public function __construct($user, $password, $vhost = "/", $insist = false, $login_method = "AMQPLAIN", $login_response = null, $locale = "en_US", PhpAmqpLib_Wire_IO_AbstractIO $io)
 {
     // save the params for the use of __clone
     $this->construct_params = func_get_args();
     if ($user && $password) {
         $login_response = new PhpAmqpLib_Wire_AMQPWriter();
         $login_response->write_table(array("LOGIN" => array('S', $user), "PASSWORD" => array('S', $password)));
         $login_response = substr($login_response->getvalue(), 4);
         //Skip the length
     } else {
         $login_response = null;
     }
     $d = self::$LIBRARY_PROPERTIES;
     while (true) {
         $this->channels = array();
         // The connection object itself is treated as channel 0
         parent::__construct($this, 0);
         $this->channel_max = 65535;
         $this->frame_max = 131072;
         $this->io = $io;
         $this->input = new PhpAmqpLib_Wire_AMQPReader(null, $this->io);
         $this->write($this->amqp_protocol_header);
         $this->wait(array($this->waitHelper->get_wait('connection.start')));
         $this->x_start_ok($d, $login_method, $login_response, $locale);
         $this->wait_tune_ok = true;
         while ($this->wait_tune_ok) {
             $this->wait(array($this->waitHelper->get_wait('connection.secure'), $this->waitHelper->get_wait('connection.tune')));
         }
         $host = $this->x_open($vhost, "", $insist);
         if (!$host) {
             return;
             // we weren't redirected
         }
         // we were redirected, close the socket, loop and try again
         $this->close_socket();
     }
 }
 /**
  * Connects to the AMQP server
  */
 protected function connect()
 {
     try {
         // Loop until we connect
         while (!$this->isConnected()) {
             // Assume we will connect, until we dont
             $this->setIsConnected(true);
             // Connect the socket
             $this->getIO()->connect();
             $this->channels = array();
             // The connection object itself is treated as channel 0
             parent::__construct($this, 0);
             $this->input = new PhpAmqpLib_Wire_AMQPReader(null, $this->getIO());
             $this->write($this->amqp_protocol_header);
             $this->wait(array($this->waitHelper->get_wait('connection.start')));
             $this->x_start_ok(self::$LIBRARY_PROPERTIES, $this->login_method, $this->login_response, $this->locale);
             $this->wait_tune_ok = true;
             while ($this->wait_tune_ok) {
                 $this->wait(array($this->waitHelper->get_wait('connection.secure'), $this->waitHelper->get_wait('connection.tune')));
             }
             $host = $this->x_open($this->vhost, '', $this->insist);
             if (!$host) {
                 return;
                 // we weren't redirected
             }
             $this->setIsConnected(false);
             $this->closeChannels();
             // we were redirected, close the socket, loop and try again
             $this->close_socket();
         }
     } catch (Exception $e) {
         // Something went wrong, set the connection status
         $this->setIsConnected(false);
         $this->closeChannels();
         throw $e;
         // Rethrow exception
     }
 }