From b1a6abbda77ce5461d103b7a1b85a56cc79fea52 Mon Sep 17 00:00:00 2001 From: Alexey Scherbakov Date: Fri, 22 Dec 2017 16:39:47 +0200 Subject: [PATCH 1/3] Fixed doc block of the Celery constructor. $persistent_messages parameter wasn't passed further to queue declaration. $connector arg defaults to null since it better fits "not specified" value. --- src/Celery.php | 33 +++++++++++++++++---------------- src/CeleryAbstract.php | 2 +- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/Celery.php b/src/Celery.php index cd50c1a..71f2d42 100644 --- a/src/Celery.php +++ b/src/Celery.php @@ -53,22 +53,23 @@ class Celery extends CeleryAbstract { /** - * @param string host - * @param string login - * @param string password - * @param string vhost AMQP vhost, may be left empty or NULL for non-AMQP backends like Redis - * @param string exchange AMQP exchange to use. For Redis it maps to queue key name. See CELERY_DEFAULT_EXCHANGE in Celery docs. (set to 'celery' when in doubt) - * @param string binding AMQP binding a.k.a. routing key. See CELERY_DEFAULT_ROUTING_KEY. (set to 'celery' when in doubt) - * @param int port - * @param string connector Which connector library to use. One of: 'pecl', 'php-amqplib', 'php-amqplib-ssl', 'redis' - * @param bool persistent_messages False = transient queue, True = persistent queue. Check "Using Transient Queues" in Celery docs (set to false when in doubt) - * @param int result_expire Expire time for result queue, milliseconds (for AMQP exchanges only) - * @param array ssl_options Used only for 'php-amqplib-ssl' connections, an associative array with values as defined here: http://php.net/manual/en/context.ssl.php + * @param string $host + * @param string $login + * @param string $password + * @param string $vhost AMQP vhost, may be left empty or NULL for non-AMQP backends like Redis + * @param string $exchange AMQP exchange to use. For Redis it maps to queue key name. See CELERY_DEFAULT_EXCHANGE in Celery docs. (set to 'celery' when in doubt) + * @param string $binding AMQP binding a.k.a. routing key. See CELERY_DEFAULT_ROUTING_KEY. (set to 'celery' when in doubt) + * @param int $port + * @param string $connector Which connector library to use. One of: 'pecl', 'php-amqplib', 'php-amqplib-ssl', 'redis' + * @param bool $persistent_messages False = transient queue, True = persistent queue. Check "Using Transient Queues" in Celery docs (set to false when in doubt) + * @see {http://docs.celeryproject.org/en/latest/userguide/optimizing.html#using-transient-queues} + * @param int $result_expire Expire time for result queue, milliseconds (for AMQP exchanges only) + * @param array $ssl_options Used only for 'php-amqplib-ssl' connections, an associative array with values as defined here: http://php.net/manual/en/context.ssl.php */ - public function __construct($host, $login, $password, $vhost, $exchange='celery', $binding='celery', $port=5672, $connector=false, $persistent_messages=false, $result_expire=0, $ssl_options=[]) + public function __construct($host, $login, $password, $vhost, $exchange='celery', $binding='celery', $port=5672, $connector=null, $persistent_messages=false, $result_expire=0, $ssl_options=[]) { - $broker_connection = [ + $backend_connection = $broker_connection = [ 'host' => $host, 'login' => $login, 'password' => $password, @@ -77,12 +78,12 @@ public function __construct($host, $login, $password, $vhost, $exchange='celery' 'binding' => $binding, 'port' => $port, 'connector' => $connector, + 'persistent_messages' => $persistent_messages, 'result_expire' => $result_expire, 'ssl_options' => $ssl_options ]; - $backend_connection = $broker_connection; - $items = $this->BuildConnection($broker_connection); - $items = $this->BuildConnection($backend_connection, true); + $this->BuildConnection($broker_connection); + $this->BuildConnection($backend_connection, true); } } diff --git a/src/CeleryAbstract.php b/src/CeleryAbstract.php index 019cd6b..a44b7fa 100644 --- a/src/CeleryAbstract.php +++ b/src/CeleryAbstract.php @@ -41,7 +41,7 @@ public function BuildConnection($connection_details, $is_backend = false) $connection_details = $this->SetDefaultValues($connection_details); $ssl = !empty($connection_details['ssl_options']); - if ($connection_details['connector'] === false) { + if (is_null($connection_details['connector'])) { $connection_details['connector'] = AbstractAMQPConnector::GetBestInstalledExtensionName($ssl); } $amqp = AbstractAMQPConnector::GetConcrete($connection_details['connector']); From 9818dabd5615781107ca626a1a00b53bf566ee71 Mon Sep 17 00:00:00 2001 From: Alexey Scherbakov Date: Fri, 22 Dec 2017 17:31:52 +0200 Subject: [PATCH 2/3] Converting $connector = false to null for backward compatibility with code that explicitly passes false. --- src/Celery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Celery.php b/src/Celery.php index 71f2d42..62b3c1b 100644 --- a/src/Celery.php +++ b/src/Celery.php @@ -77,7 +77,7 @@ public function __construct($host, $login, $password, $vhost, $exchange='celery' 'exchange' => $exchange, 'binding' => $binding, 'port' => $port, - 'connector' => $connector, + 'connector' => $connector !== false ? $connector : null, 'persistent_messages' => $persistent_messages, 'result_expire' => $result_expire, 'ssl_options' => $ssl_options From cd19ad49d729917ea7be0dee52e974595cc1179d Mon Sep 17 00:00:00 2001 From: Alexey Scherbakov Date: Wed, 27 Dec 2017 16:05:48 +0200 Subject: [PATCH 3/3] Python's Celery creates the following binding exchange "celery" - routing key "celery" - queue "celery" --- src/AMQPLibConnector.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/AMQPLibConnector.php b/src/AMQPLibConnector.php index a862914..93ba043 100644 --- a/src/AMQPLibConnector.php +++ b/src/AMQPLibConnector.php @@ -103,7 +103,8 @@ public function PostToExchange($connection, $details, $task, $params) $ch->queue_bind( $details['binding'], /* queue name - "celery" */ - $details['exchange'] /* exchange name - "celery" */ + $details['exchange'], /* exchange name - "celery" */ + $details['binding'] /* routing key - "celery" */ ); $msg = new \PhpAmqpLib\Message\AMQPMessage(