@@ -9,6 +9,12 @@ |
||
| 9 | 9 | |
| 10 | 10 | private static $amqpLazyConnection; |
| 11 | 11 | |
| 12 | + /** |
|
| 13 | + * @param string $host |
|
| 14 | + * @param string $port |
|
| 15 | + * @param string $user |
|
| 16 | + * @param string $password |
|
| 17 | + */ |
|
| 12 | 18 | public static function getInstance($host, $port, $user, $password, $vhost = '/') |
| 13 | 19 | { |
| 14 | 20 | if(null === static::$amqpLazyConnection) { |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | |
| 12 | 12 | public static function getInstance($host, $port, $user, $password, $vhost = '/') |
| 13 | 13 | { |
| 14 | - if(null === static::$amqpLazyConnection) { |
|
| 14 | + if (null === static::$amqpLazyConnection) { |
|
| 15 | 15 | static::$amqpLazyConnection = new AMQPLazyConnection($host, $port, $user, $password, $vhost); |
| 16 | 16 | } |
| 17 | 17 | |
@@ -51,6 +51,9 @@ |
||
| 51 | 51 | $this->channel->wait(); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | + /** |
|
| 55 | + * @param callable $callback |
|
| 56 | + */ |
|
| 54 | 57 | private function initialize($callback) |
| 55 | 58 | { |
| 56 | 59 | $this->rabbitMQMessageHandler->setEventCallback($callback); |
@@ -3,7 +3,6 @@ |
||
| 3 | 3 | namespace Cmp\Queue\Infrastructure\RabbitMQ; |
| 4 | 4 | |
| 5 | 5 | use Cmp\DomainEvent\Domain\Event\DomainEvent; |
| 6 | -use Cmp\DomainEvent\Domain\Subscriber\AbstractSubscriber; |
|
| 7 | 6 | use Cmp\Queue\Domain\Reader\QueueReader; |
| 8 | 7 | use Psr\Log\LoggerInterface; |
| 9 | 8 | |
@@ -54,9 +54,9 @@ |
||
| 54 | 54 | |
| 55 | 55 | $channel->exchange_declare($this->exchange, 'topic', false, true, false); |
| 56 | 56 | |
| 57 | - list($queueName, ,) = $channel->queue_declare($this->queue, false, false, true, true); |
|
| 57 | + list($queueName,,) = $channel->queue_declare($this->queue, false, false, true, true); |
|
| 58 | 58 | |
| 59 | - foreach($this->domainTopics as $domainTopic) { |
|
| 59 | + foreach ($this->domainTopics as $domainTopic) { |
|
| 60 | 60 | $this->logger->info('Binding Topic:' . $domainTopic); |
| 61 | 61 | $channel->queue_bind($queueName, $this->exchange, $domainTopic); |
| 62 | 62 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | public function notify(DomainEvent $domainEvent) |
| 46 | 46 | { |
| 47 | 47 | $this->logger->debug('Domain Event received, notifying subscribers'); |
| 48 | - foreach($this->subscriptors as $subscriptor) { |
|
| 48 | + foreach ($this->subscriptors as $subscriptor) { |
|
| 49 | 49 | if ($subscriptor->isSubscribed($domainEvent)) { |
| 50 | 50 | $subscriptor->notify($domainEvent); |
| 51 | 51 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | public function start() |
| 56 | 56 | { |
| 57 | - while(true) { |
|
| 57 | + while (true) { |
|
| 58 | 58 | $this->queueReader->process(array($this, 'notify')); |
| 59 | 59 | } |
| 60 | 60 | } |
@@ -56,7 +56,7 @@ |
||
| 56 | 56 | $this->channel = $this->rabbitMQInitializer->initialize(); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - foreach($messages as $message) { |
|
| 59 | + foreach ($messages as $message) { |
|
| 60 | 60 | $encodedMessage = json_encode($message); |
| 61 | 61 | $this->logger->debug('Writing:' . $encodedMessage); |
| 62 | 62 | $msg = new AMQPMessage($encodedMessage, array('delivery_mode' => 2)); |
@@ -48,7 +48,7 @@ |
||
| 48 | 48 | * @param string $queue |
| 49 | 49 | * @param string $vhost |
| 50 | 50 | */ |
| 51 | - public function __construct($host, $port, $user, $password, $exchange, $queue='', $vhost='/') |
|
| 51 | + public function __construct($host, $port, $user, $password, $exchange, $queue = '', $vhost = '/') |
|
| 52 | 52 | { |
| 53 | 53 | $this->host = $host; |
| 54 | 54 | $this->port = $port; |
@@ -72,8 +72,8 @@ |
||
| 72 | 72 | { |
| 73 | 73 | $channel = $this->connection->channel(); |
| 74 | 74 | |
| 75 | - $exchangeDelayed = self::DELAY_QUEUE_PREFIX.$delay.$this->exchangeName; |
|
| 76 | - $queueDelayed = self::DELAY_QUEUE_PREFIX.$delay.'Queue'; |
|
| 75 | + $exchangeDelayed = self::DELAY_QUEUE_PREFIX . $delay . $this->exchangeName; |
|
| 76 | + $queueDelayed = self::DELAY_QUEUE_PREFIX . $delay . 'Queue'; |
|
| 77 | 77 | |
| 78 | 78 | // Delay Queue |
| 79 | 79 | $channel->exchange_declare($exchangeDelayed, 'fanout', false, true, true); |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | |
| 42 | 42 | if ($numOfDomainObjects === 1) { |
| 43 | 43 | $this->writeOne($this->messages[0]); |
| 44 | - } else if($numOfDomainObjects > 1) { |
|
| 44 | + } else if ($numOfDomainObjects > 1) { |
|
| 45 | 45 | $this->writeSome($this->messages); |
| 46 | 46 | } |
| 47 | 47 | $this->messages = []; |
@@ -54,7 +54,7 @@ |
||
| 54 | 54 | |
| 55 | 55 | $channel->exchange_declare($this->exchange, 'fanout', false, true, false); |
| 56 | 56 | |
| 57 | - list($queueName, ,) = $channel->queue_declare($this->queue, false, true, false, false); |
|
| 57 | + list($queueName,,) = $channel->queue_declare($this->queue, false, true, false, false); |
|
| 58 | 58 | |
| 59 | 59 | $channel->queue_bind($queueName, $this->exchange); |
| 60 | 60 | |