I have a problem with sending messages on every request. The current situation is that the message is sent after the 2nd or 3rd request. Below is the code of the function responsible for sending.
require_once __DIR__ . '../../vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPSSLConnection;
use PhpAmqpLib\Message\AMQPMessage;
function sendToRabbitMQ($content, $queue = 'queue-name') {
$ssl_opts = ['cafile' => __DIR__ . '/ssl/ca_certificate.pem',
'local_cert' => __DIR__ . '/ssl/client_certificate.pem',
'local_pk' => __DIR__ . '/ssl/client_key.pem',
'ssl_version' => 'tlsv1.2',
'verify_peer' => true,
'allow_self_signed' => true,
'verify_peer_name' => true,
];
$options = [ 'connection_timeout' => 10 ];
if($content === false OR empty($content)) {
return false;
}
try {
$connection = new AMQPSSLConnection('server.host', 5671, 'user', 'password', 'vhost', $ssl_opts, $options);
$msg = new AMQPMessage($content);
$channel = $connection->channel();
$channel->queue_declare($queue, false, true, false, false);
$channel->basic_publish($msg, '', $queue);
$channel->close();
$connection->close();
} catch(Exception $e) {
return false;
}
return true;
}
In RabbitMQ log when failed I get:
client unexpectedly closed TCP connection
Unfortunately, Exception returns nothing.