Commit 1f9d5152 authored by hlarget's avatar hlarget 🥑

Merge branch '1-pouvoir-se-connecter-a-rabbitmq-avec-une-uri-aussi' into 'master'

Resolve "Pouvoir se connecter a rabbitmq avec une URI aussi"

Closes #1

See merge request open-source/agrabbitmq!4
parents 20390d68 07daabf9
vendor
./composer.lock
.idea
\ No newline at end of file
......@@ -4,7 +4,7 @@
"symfony/validator": ">=3.2",
"doctrine/annotations": ">=1.4",
"php-amqplib/php-amqplib": "2.7.0",
"aboutgoods/php-jakku-client": "dev-master"
"aboutgoods/url": "^2.0"
},
"autoload": {
"psr-4": {
......@@ -23,4 +23,4 @@
"url": "https://gitlab.agoods.fr/open-source/agrabbitmq.git"
}
]
}
\ No newline at end of file
}
This diff is collapsed.
......@@ -5,6 +5,7 @@ namespace Aboutgoods\RabbitMQ;
use PhpAmqpLib\Channel\AMQPChannel;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
use Aboutgoods\Url\Url;
class Client
{
......@@ -22,12 +23,18 @@ class Client
private $login;
private $password;
public function __construct($address = "localhost", $port = 5672, $login = "guest", $password = "guest")
public function __construct($address = "rabbitmq://guest:guest@localhost:5672/jakku")
{
$this->address = $address;
$this->port = $port;
$this->login = $login;
$this->password = $password;
$url = Url::fromString($address);
if (filter_var($address, FILTER_VALIDATE_URL))
{
$userInfos = explode(":", $url->getUserInfo());
$this->channelName = ltrim($url->getPath(), "/");
$this->address = $url->getHost();
$this->port = $url->getPort();
$this->login = $userInfos[0];
$this->password = $userInfos[1];
}
}
public function connect()
......@@ -50,7 +57,9 @@ class Client
$auto_delete = true
) {
$this->channel = $this->connection->channel();
$this->channelName = $queue;
if(!isset($this->channelName)){
$this->channelName = $queue;
}
return $this->channel->queue_declare($queue, $passive, $durable, $exclusive, $auto_delete);
}
......
......@@ -4,7 +4,6 @@ namespace Aboutgoods\RabbitMQ;
use Aboutgoods\RabbitMQ\Exceptions\ClientNotConnectedException;
use Aboutgoods\RabbitMQ\Exceptions\InvalidObjectException;
use Aboutgoods\RabbitMQ\Tools\JsonSerializer;
use Aboutgoods\Jakku\DataBag\AbstractDataBag;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\Validation;
use Doctrine\Common\Annotations\AnnotationRegistry;
......@@ -17,10 +16,7 @@ class RMQConnector
{
if (self::$client == null) {
self::$client = new Client(
$config["address"] ?? "127.0.0.1",
$config["port"] ?? 5672,
$config["login"] ?? "guest",
$config["password"] ?? "guest"
$config["address"] ?? "rabbitmq://guest:guest@127.0.0.1:5672"
);
self::$client->connect();
self::$client->connectToChannel($config["queue"] ?? "jakku", false, true, false, false);
......@@ -43,7 +39,7 @@ class RMQConnector
return self::$client;
}
public static function emit(AbstractDataBag $dataBag)
public static function emit($dataBag)
{
if ( ! class_exists('Doctrine\Common\Annotations\AnnotationRegistry', false)
&& class_exists('Doctrine\Common\Annotations\AnnotationRegistry')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment