-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Nous avons constaté un problème concernant les rejets. Après plusieurs investigations, on est tombé sur la posisbilité que ce soit le fait que trop de connexion à RabbitMQ soient ouvertes.
En fait, dans chaque step, nous avons la méthode withAuthentication de l'objet Kiboko\Component\Flow\RabbitMQ\Rejection qui est appelé. Sauf que cette méthode instancie un nouveau client à chaque fois, et appelle la méthode connect a chaque fois.
Kiboko\Component\Flow\RabbitMQ\Rejection::withAuthentication(...)public static function withAuthentication(
string $stepUuid,
string $host,
string $vhost,
string $topic,
?string $user,
?string $password,
?string $exchange = null,
?int $port = null,
): self {
$connection = new Client([
'host' => $host,
'port' => $port,
'vhost' => $vhost,
'user' => $user,
'password' => $password,
]);
$connection->connect();
return new self($connection, stepUuid: $stepUuid, topic: $topic, exchange: $exchange);
}Solution :
Dans le Package https://github.com/php-etl/rabbitmq-flow, il faut ajouter une classe qui va gérer les instances du client.
class SharedAuthenticationMiddleware
{
private static ?\Bunny\Client $instance = null;
public static function getInstance(
string $host,
string $vhost,
?string $user,
?string $password,
?int $port = null,
): \Bunny\Client {
if (null === self::$instance) {
self::$instance = new \Bunny\Client([
'host' => $host,
'port' => $port,
'vhost' => $vhost,
'user' => $user,
'password' => $password,
]);
self::$instance->connect();
}
return self::$instance;
}
}Dans https://github.com/php-etl/satellite, il faut modifier le code généré pour avoir quelque chose du genre
new \Kiboko\Component\Flow\RabbitMQ\Rejection(\Kiboko\Component\Flow\RabbitMQ\SharedAuthenticationMiddleware::getInstance(host: getenv("RABBITMQ_HOST"), vhost: getenv("RABBITMQ_VHOST"), user: getenv("RABBITMQ_USER"), password: getenv("RABBITMQ_PASSWORD"), port: getenv("RABBITMQ_PORT")), stepUuid: '6760085278df6', topic: 'contacts_1954_eshop')Et, il faudrait avoir une option shared pour pouvoir utiliser l'ancienne méthode ou la nouvelle facilement

