Answer the question
In order to leave comments, you need to log in
How to keep one connection to RabbitMQ?
Hello everyone and Happy New Year!
I have an endpoint in symfony, when accessed, it connects to rabbitmq and sends a message, then closes the connection. The problem is that there can be about 3000 such calls per second, and all this time I constantly have connections and close them. The question is, is it possible to somehow save one connection and use it all the time?
The code:
$connection = new AMQPStreamConnection(
$_ENV['RABBIT_IP'],
$_ENV['RABBIT_PORT'],
$_ENV['RABBIT_USER'],
$_ENV['RABBIT_PASSWORD'],
'/',
false,
'AMQPLAIN',
null,
'en_US',
30, //Connection Timeout
30, // Read/Write Timeout
null,
false,
60
);
$channel = $connection->channel();
$channel->queue_declare('RequestLog', false, false, false, false);
$msg = new AMQPMessage($request->getContent());
$channel->basic_publish($msg, 'clickhouse-exchange', 'RequestLog');
$channel->close();
$connection->close();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question