Код: Выделить всё
function connect($host, $port, $user, $password, $vhost = '/') {
return AMQPStreamConnection::create_connection([
['host' => $host, 'port' => $port, 'user' => $user, 'password' => $password, 'vhost' => $vhost]
],
[
'insist' => false,
'login_method' => 'AMQPLAIN',
'login_response' => null,
'locale' => 'en_US',
'connection_timeout' => 3.0,
'read_write_timeout' => 3.0,
'context' => null,
'keepalive' => true,
'heartbeat' => 0
]);
}
public function __construct($host, $port, $user, $password, $queue, $vhost = '/')
{
try {
$this->connection = $this->connect($host, $port, $user, $password, $vhost);
$this->channel = $this->connection->channel();
$this->queue = $queue;
$this->channel->queue_declare($queue, false, true, false, false);
} catch (AMQPConnectionClosedException $e) {
log_message('error', 'RabbitMQ connection error: ' . $e->getMessage());
throw $e;
} catch (AMQPIOException $e) {
log_message('error', 'RabbitMQ IO error: ' . $e->getMessage());
throw $e;
} catch (\Exception $e) {
log_message('error', 'RabbitMQ general error: ' . $e->getMessage());
throw $e;
}
}
Код: Выделить всё
connection ([::1]:52990 -> [::1]:5672): user 'xxxx' authenticated and granted access to vhost 'my_vhost'
Код: Выделить всё
$this->channel = $this->connection->channel();
Подробнее здесь: https://stackoverflow.com/questions/787 ... to-channel