mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-24 02:13:15 +00:00
fix connection
This commit is contained in:
@@ -45,6 +45,12 @@ class WorkerExecuteCommand extends Command
|
|||||||
/** @var AMQPChannel $channel */
|
/** @var AMQPChannel $channel */
|
||||||
$channel = $serverConnection->getChannel();
|
$channel = $serverConnection->getChannel();
|
||||||
|
|
||||||
|
if ($channel == null) {
|
||||||
|
$output->writeln("Can't connect to rabbit, check configuration!");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/** @var WorkerInvoker $workerInvoker */
|
/** @var WorkerInvoker $workerInvoker */
|
||||||
$workerInvoker = $this->container['alchemy_worker.worker_invoker'];
|
$workerInvoker = $this->container['alchemy_worker.worker_invoker'];
|
||||||
|
|
||||||
|
|||||||
@@ -80,12 +80,18 @@ class AMQPConnection
|
|||||||
public function getConnection()
|
public function getConnection()
|
||||||
{
|
{
|
||||||
if (!isset($this->connection)) {
|
if (!isset($this->connection)) {
|
||||||
$this->connection = new AMQPStreamConnection(
|
try{
|
||||||
$this->hostConfig['host'],
|
$this->connection = new AMQPStreamConnection(
|
||||||
$this->hostConfig['port'],
|
$this->hostConfig['host'],
|
||||||
$this->hostConfig['user'],
|
$this->hostConfig['port'],
|
||||||
$this->hostConfig['password'],
|
$this->hostConfig['user'],
|
||||||
$this->hostConfig['vhost']);
|
$this->hostConfig['password'],
|
||||||
|
$this->hostConfig['vhost']
|
||||||
|
);
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->connection;
|
return $this->connection;
|
||||||
@@ -94,26 +100,40 @@ class AMQPConnection
|
|||||||
public function getChannel()
|
public function getChannel()
|
||||||
{
|
{
|
||||||
if (!isset($this->channel)) {
|
if (!isset($this->channel)) {
|
||||||
$this->channel = $this->getConnection()->channel();
|
$this->getConnection();
|
||||||
}
|
if (isset($this->connection)) {
|
||||||
|
$this->channel = $this->connection->channel();
|
||||||
|
|
||||||
return $this->channel;
|
return $this->channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return $this->channel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function declareExchange()
|
public function declareExchange()
|
||||||
{
|
{
|
||||||
$this->channel->exchange_declare(self::ALCHEMY_EXCHANGE, 'direct', false, true, false);
|
if (!isset($this->channel)) {
|
||||||
$this->channel->exchange_declare(self::RETRY_ALCHEMY_EXCHANGE, 'direct', false, true, false);
|
$this->channel->exchange_declare(self::ALCHEMY_EXCHANGE, 'direct', false, true, false);
|
||||||
|
$this->channel->exchange_declare(self::RETRY_ALCHEMY_EXCHANGE, 'direct', false, true, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $queueName
|
* @param $queueName
|
||||||
* @return AMQPChannel
|
* @return AMQPChannel|null
|
||||||
*/
|
*/
|
||||||
public function setQueue($queueName)
|
public function setQueue($queueName)
|
||||||
{
|
{
|
||||||
if (!isset($this->channel)) {
|
if (!isset($this->channel)) {
|
||||||
$this->getChannel();
|
$this->getChannel();
|
||||||
|
if (!isset($this->channel)) {
|
||||||
|
// can't connect to rabbit
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
$this->declareExchange();
|
$this->declareExchange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,12 @@ class MessageHandler
|
|||||||
|
|
||||||
$channel = $serverConnection->getChannel();
|
$channel = $serverConnection->getChannel();
|
||||||
|
|
||||||
|
if ($channel == null) {
|
||||||
|
$this->messagePublisher->pushLog("Can't connect to rabbit, check configuration!", "error");
|
||||||
|
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
// define consume callbacks
|
// define consume callbacks
|
||||||
$callback = function (AMQPMessage $message) use ($channel, $workerInvoker, $publisher) {
|
$callback = function (AMQPMessage $message) use ($channel, $workerInvoker, $publisher) {
|
||||||
|
|
||||||
|
|||||||
@@ -96,6 +96,12 @@ class MessagePublisher
|
|||||||
|
|
||||||
$channel = $this->serverConnection->setQueue($queueName);
|
$channel = $this->serverConnection->setQueue($queueName);
|
||||||
|
|
||||||
|
if ($channel == null) {
|
||||||
|
$this->pushLog("Can't connect to rabbit, check configuration!", "error");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
$exchange = in_array($queueName, AMQPConnection::$defaultQueues) ? AMQPConnection::ALCHEMY_EXCHANGE : AMQPConnection::RETRY_ALCHEMY_EXCHANGE;
|
$exchange = in_array($queueName, AMQPConnection::$defaultQueues) ? AMQPConnection::ALCHEMY_EXCHANGE : AMQPConnection::RETRY_ALCHEMY_EXCHANGE;
|
||||||
$channel->basic_publish($msg, $exchange, $queueName);
|
$channel->basic_publish($msg, $exchange, $queueName);
|
||||||
|
|
||||||
@@ -137,6 +143,12 @@ class MessagePublisher
|
|||||||
$msg->set('application_headers', $headers);
|
$msg->set('application_headers', $headers);
|
||||||
|
|
||||||
$channel = $this->serverConnection->setQueue($queueName);
|
$channel = $this->serverConnection->setQueue($queueName);
|
||||||
|
if ($channel == null) {
|
||||||
|
$this->pushLog("Can't connect to rabbit, check configuration!", "error");
|
||||||
|
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
$channel->basic_publish($msg, AMQPConnection::RETRY_ALCHEMY_EXCHANGE, $queueName);
|
$channel->basic_publish($msg, AMQPConnection::RETRY_ALCHEMY_EXCHANGE, $queueName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user