From 657d242ccb5fad19a08fe1cdcaa7637419acdf68 Mon Sep 17 00:00:00 2001 From: Faouzi CHAACHOUA Date: Thu, 26 May 2016 16:18:19 +0200 Subject: [PATCH 1/2] [FEATURE#28934] RabbitMQ v2 - Utilisation du rabbitmq-service-provider en v2 --- composer.json | 2 +- src/SPrinter.php | 42 ++++++++++++++++++++------------- src/SPrinterServiceProvider.php | 18 +++++++------- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/composer.json b/composer.json index ca7c483..f45fafd 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "require": { "php": ">=5.5", "silex/silex": "~2.0@dev", - "etna/rabbitmq-service-provider": "0.x" + "etna/rabbitmq-service-provider": "2.x-dev" }, "config": { "bin-dir": "bin" diff --git a/src/SPrinter.php b/src/SPrinter.php index aa97dfa..3f7df77 100644 --- a/src/SPrinter.php +++ b/src/SPrinter.php @@ -2,16 +2,30 @@ namespace ETNA\Silex\Provider\SPrinter; -use ETNA\Silex\Provider\RabbitMQ\Queue; +use OldSound\RabbitMqBundle\RabbitMq\Producer; +use Silex\Application; + /** * */ class SPrinter { - public function __construct($exchange, $options) + public function __construct($app) { - $this->exchange = $exchange; - $this->routing_key = $options["default.routing_key"]; + // On crée un producer pour publier des jobs + $connection = $app['rabbit.connections']['default']; + $producer = new Producer($connection); + $producer->setExchangeOptions([ + "name" => "SPrinter", + "channel" => "default", + "type" => "direct", + "passive" => false, + "durable" => true, + "auto_delete" => false, + ]); + + $this->producer = $producer; + $this->routing_key = $app["sprinter.options"]["default.routing_key"]; } public function getDefaultRoutingKey() @@ -19,28 +33,24 @@ public function getDefaultRoutingKey() return $this->routing_key; } + public function getProducer() + { + return $this->producer; + } + public function sendPrint($template, $data, $print_flag, $routing_key = null, $opt = null) { - $queue_opt = [ - "passive" => false, - "durable" => true, - "exclusive" => false, - "auto_delete" => false, - ]; - $params = [ + $print_params = [ "template" => $template, "data" => $data, "printflag" => $print_flag ]; if ($opt) { - $params = array_merge($params, $opt); + $print_params = array_merge($print_params, $opt); } $routing_key = $routing_key ?: $this->routing_key; - // crée la queue au besoin - $queue = new Queue($routing_key, $this->exchange, $this->exchange->getChannel(), $queue_opt); - - $this->exchange->send($params, $routing_key); + $this->producer->publish($print_params, $routing_key); } } diff --git a/src/SPrinterServiceProvider.php b/src/SPrinterServiceProvider.php index c54882e..6c831ca 100644 --- a/src/SPrinterServiceProvider.php +++ b/src/SPrinterServiceProvider.php @@ -2,7 +2,6 @@ namespace ETNA\Silex\Provider\SPrinter; -use Silex\Application; use Pimple\ServiceProviderInterface; use Pimple\Container; @@ -13,12 +12,12 @@ class SPrinterServiceProvider implements ServiceProviderInterface { public function register(Container $app) { - if (!isset($app["sprinter.options"]) || !isset($app["sprinter.options"]["default.routing_key"])) { + if (false === isset($app["sprinter.options"]) || false === isset($app["sprinter.options"]["default.routing_key"])) { $environment_key = "{$app["application_name"]}_SPRINTER_ROUTING_KEY"; $routing_key = getenv(strtoupper($environment_key)); if (false === $routing_key) { - throw new Exception("No sprinter routing key found for environment {$environment_key}"); + throw new \Exception("No sprinter routing key found for environment {$environment_key}"); } $app["sprinter.options"] = [ @@ -26,10 +25,13 @@ public function register(Container $app) ]; } - $app["sprinter"] = $app->share( - function (Application $app) { - return new SPrinter($app["amqp.exchanges"]["SPrinter"], $app["sprinter.options"]); - } - ); + // On vérifie que la connection rmq est bien settée + if (false === isset($app['rabbit.connections']) || false === isset($app['rabbit.connections']['default'])) { + throw new \Exception("RabbitMQ default connection not set"); + } + + $app["sprinter"] = function ($app) { + return new SPrinter($app); + }; } } From b03703d9c49ae868d5f0dd89ff4f3577ee6b9642 Mon Sep 17 00:00:00 2001 From: Faouzi CHAACHOUA Date: Fri, 27 May 2016 10:38:28 +0200 Subject: [PATCH 2/2] [FEATURE#28934] Heroku https - Heroku en https pour composer --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f45fafd..15743f3 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "repositories": [ { "type": "composer", - "url": "http://blu-composer.herokuapp.com/" + "url": "https://blu-composer.herokuapp.com/" } ] }