...
 
Commits (2)
......@@ -23,13 +23,13 @@ class Client
private $login;
private $password;
public function __construct($address = "rabbitmq://guest:guest@localhost:5672/jakku")
public function __construct($address = 'rabbitmq://guest:guest@localhost:5672/jakku')
{
$url = Url::fromString($address);
if (filter_var($address, FILTER_VALIDATE_URL))
{
$userInfos = explode(":", $url->getUserInfo());
$this->channelName = ltrim($url->getPath(), "/");
$userInfos = explode(':', $url->getUserInfo());
$this->channelName = ltrim($url->getPath(), '/');
$this->address = $url->getHost();
$this->port = $url->getPort();
$this->login = $userInfos[0];
......@@ -37,12 +37,12 @@ class Client
}
}
public function connect()
public function connect(): void
{
$this->connection = new AMQPStreamConnection($this->address, $this->port, $this->login, $this->password);
}
public function setConnection($connection)
public function setConnection($connection): void
{
if ($connection instanceof AMQPStreamConnection) {
$this->connection = $connection;
......@@ -50,7 +50,6 @@ class Client
}
public function connectToChannel(
$queue = '',
$passive = false,
$durable = false,
$exclusive = false,
......@@ -58,12 +57,12 @@ class Client
) {
$this->channel = $this->connection->channel();
if(!isset($this->channelName)){
$this->channelName = $queue;
$this->channelName = 'jakku';
}
return $this->channel->queue_declare($queue, $passive, $durable, $exclusive, $auto_delete);
return $this->channel->queue_declare($this->channelName, $passive, $durable, $exclusive, $auto_delete);
}
public function send($content)
public function send($content): bool
{
$msg = new AMQPMessage($content, ['delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT]);
$this->channel->basic_publish($msg, '', $this->channelName);
......
......@@ -16,10 +16,10 @@ class RMQConnector
{
if (self::$client == null) {
self::$client = new Client(
$config["address"] ?? "rabbitmq://guest:guest@127.0.0.1:5672"
$config["address"] ?? "rabbitmq://guest:guest@127.0.0.1:5672/jakku"
);
self::$client->connect();
self::$client->connectToChannel($config["queue"] ?? "jakku", $config["passive"] ?? false, $config["durable"] ?? true, $config["exclusive"] ?? false,
self::$client->connectToChannel($config["passive"] ?? false, $config["durable"] ?? true, $config["exclusive"] ?? false,
$config["auto_delete"] ?? false); }
return self::class;
......