/** * @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) { 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; } }
public function disconnect() { if (!$this->amqp_connection) { return; } if ($this->amqp_connection->isConnected()) { $this->amqp_connection->close(); } $this->amqp_connection = null; }
/** * Actual health check logic. * * @param HealthBuilder $builder * * @throws \Exception any Exception that should create a Status::DOWN * system status. */ protected function doHealthCheck(HealthBuilder $builder) { try { $this->connection->reconnect(); $serverProperties = $this->connection->getServerProperties(); $builder->withDetail('version', $serverProperties['version'][1]); } catch (\Exception $e) { $builder->down($e); return; } $builder->up(); }
/** * {@inheritdoc} */ protected function setUp() { if (!isset($_SERVER['AMQP_HOST'])) { $this->markTestSkipped('This test require AMQP Server, use AMQP_HOST, AMQP_PORT, AMQP_USER, AMQP_PASSWORD, AMQP_VHOST environment variables to set connection details'); } $this->exchange = uniqid('phpunit.'); $env = function ($key, $default = null) { return isset($_SERVER[$key]) ? $_SERVER[$key] : $default; }; $this->connection = new AMQPStreamConnection($env('AMQP_HOST', 'localhost'), $env('AMQP_PORT', 5672), $env('AMQP_USER', 'guest'), $env('AMQP_PASSWORD', 'guest'), $env('AMQP_VHOST', '/')); $this->channel = $this->connection->channel(); $this->channel->exchange_declare($this->exchange, 'fanout'); $this->client = new ServiceBus(new Driver($this->channel, $this->exchange, new JsonEncoder())); $this->initialize(); }
/** * @param AbstractConnection $host * @param string $port * @param string $user * @param string $password * @param string $vhost * @param bool $insist * @param string $login_method * @param null $login_response * @param string $locale * @param int $connection_timeout * @param int $read_write_timeout * @param null $context * @param bool $keepalive */ public function __construct($host, $port, $user, $password, $vhost = '/', $insist = false, $login_method = 'AMQPLAIN', $login_response = null, $locale = 'en_US', $connection_timeout = 3, $read_write_timeout = 3, $context = null, $keepalive = false, $heartbeat = 0) { $io = new StreamIO($host, $port, $connection_timeout, $read_write_timeout, $context, $keepalive, $heartbeat); parent::__construct($user, $password, $vhost, $insist, $login_method, $login_response, $locale, $io, $heartbeat); // save the params for the use of __clone, this will overwrite the parent $this->construct_params = func_get_args(); }
public function __construct($host, $port, $user, $password, $vhost = "/", $insist = false, $login_method = "AMQPLAIN", $login_response = null, $locale = "en_US", $connection_timeout = 3, $read_write_timeout = 3, $context = null) { $io = new StreamIO($host, $port, $connection_timeout, $read_write_timeout, $context); $this->sock = $io->get_socket(); parent::__construct($user, $password, $vhost, $insist, $login_method, $login_response, $locale, $io); // save the params for the use of __clone, this will overwrite the parent $this->construct_params = func_get_args(); }
/** * @return $this */ public function disconnect() { if ($this->connection) { $this->connection->close(); $this->connection = null; } return $this; }
/** * @return \PhpAmqpLib\Channel\AMQPChannel */ public function channel() { try { // Create channel if ($this->channel === null) { // Connect if not connected if (!$this->connection->isConnected()) { $this->connection->reconnect(); } // Create channel $this->channel = $this->getConnection()->channel(); } return $this->channel; } catch (\Exception $e) { // The exceptions thrown by the library are cryptic at best. You may very well get seemingly unrelated a protocol error etc. // Throw a more descriptive exception. throw new \InvalidArgumentException("Failed to create the AMQP channel. This may be related to a misconfiguration of the connection or channel.", 0, $e); } }
/** * Shut it down, delete exchanges, queues, close connections and channels */ public function tearDown() { if ($this->ch) { $this->ch->exchange_delete($this->exchange); $this->ch->queue_delete($this->queue); $this->ch->close(); } if ($this->conn) { $this->conn->close(); } }
public function closeConnection() { if ($this->channel) { $this->channel->close(); } if ($this->connection) { $this->connection->close(); } $this->isQueueSetup = false; return $this; }
public function __construct($host, $port, $user, $password, $vhost = "/", $insist = false, $login_method = "AMQPLAIN", $login_response = null, $locale = "en_US", $connection_timeout = 3, $read_write_timeout = 3, $context = null) { $io = new StreamIO($host, $port, $connection_timeout, $read_write_timeout, $context); $this->sock = $io->get_socket(); parent::__construct($user, $password, $vhost, $insist, $login_method, $login_response, $locale, $io); }
/** * @param \PhpAmqpLib\Channel\AMQPChannel $ch * @param \PhpAmqpLib\Connection\AbstractConnection $conn */ function shutdown($ch, $conn) { $ch->close(); $conn->close(); }
/** * @param string $host * @param int $port * @param string $user * @param string $password * @param string $vhost * @param bool $insist * @param string $login_method * @param null $login_response * @param string $locale * @param int $timeout * @param bool $keepalive */ public function __construct($host, $port, $user, $password, $vhost = '/', $insist = false, $login_method = 'AMQPLAIN', $login_response = null, $locale = 'en_US', $timeout = 3, $keepalive = false) { $io = new SocketIO($host, $port, $timeout, $keepalive); parent::__construct($user, $password, $vhost, $insist, $login_method, $login_response, $locale, $io); }
protected function tearDownAmqp() { $this->conn->close(); }
public function __construct($host, $port, $user, $password, $vhost = "/", $insist = false, $login_method = "AMQPLAIN", $login_response = null, $locale = "en_US", $timeout = 3) { $io = new SocketIO($host, $port, $timeout); parent::__construct($user, $password, $vhost, $insist, $login_method, $login_response, $locale, $io); }
/** * @inheritdoc */ public function reconnect() : bool { $this->connection->reconnect(); return $this->isConnected(); }
protected function send_method_frame($method_sig, $args = "") { $this->connection->send_channel_method_frame($this->channel_id, $method_sig, $args); }
/** * This is here for performance reasons to batch calls to fwrite from basic.publish * * @param $method_sig * @param string $args * @param null $pkt * @return null|\PhpAmqpLib\Wire\AMQPWriter */ protected function prepare_method_frame($method_sig, $args = '', $pkt = null) { return $this->connection->prepare_channel_method_frame($this->channel_id, $method_sig, $args, $pkt); }
/** * BaseAmqp constructor. * @param AbstractConnection $connection */ public function __construct(AbstractConnection $connection) { $this->connection = $connection; $this->channel = $this->connection->channel(); }