@@ -26,7 +26,6 @@ |
||
26 | 26 | /** |
27 | 27 | * MessageHandler constructor. |
28 | 28 | * @param JSONMessageFactory $jsonMessageFactory |
29 | - * @param callable $callback |
|
30 | 29 | */ |
31 | 30 | public function __construct(JSONMessageFactory $jsonMessageFactory) |
32 | 31 | { |
@@ -117,7 +117,7 @@ |
||
117 | 117 | */ |
118 | 118 | protected function initialize() |
119 | 119 | { |
120 | - if($this->channel) { |
|
120 | + if ($this->channel) { |
|
121 | 121 | return; |
122 | 122 | } |
123 | 123 | $this->logger->info('Connecting to RabbitMQ'); |
@@ -16,7 +16,7 @@ |
||
16 | 16 | protected $password; |
17 | 17 | protected $vHost; |
18 | 18 | |
19 | - public function __construct($host, $port, $user, $password, $vHost='/') |
|
19 | + public function __construct($host, $port, $user, $password, $vHost = '/') |
|
20 | 20 | { |
21 | 21 | $this->host = $host; |
22 | 22 | $this->port = $port; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | { |
68 | 68 | $this->delay = $delay; |
69 | 69 | $this->exchangeName = $exchangeName; |
70 | - $this->delayedExchangeName = self::DELAY_QUEUE_PREFIX.$this->delay.$this->exchangeName; |
|
70 | + $this->delayedExchangeName = self::DELAY_QUEUE_PREFIX . $this->delay . $this->exchangeName; |
|
71 | 71 | $this->logger = $logger; |
72 | 72 | $this->channel = $channel; |
73 | 73 | } |
@@ -81,15 +81,15 @@ discard block |
||
81 | 81 | { |
82 | 82 | $this->initialize(); |
83 | 83 | try { |
84 | - foreach($messages as $message) { |
|
84 | + foreach ($messages as $message) { |
|
85 | 85 | $encodedMessage = json_encode($message); |
86 | 86 | $this->logger->debug('Writing:' . $encodedMessage); |
87 | 87 | $msg = new AMQPMessage($encodedMessage, array('delivery_mode' => 2)); |
88 | 88 | $this->channel->batch_basic_publish($msg, $this->delayedExchangeName, $message->getName()); |
89 | 89 | } |
90 | 90 | $this->channel->publish_batch(); |
91 | - } catch(\Exception $exception) { |
|
92 | - $this->logger->error('Error writing messages: '.$exception->getMessage()); |
|
91 | + } catch (\Exception $exception) { |
|
92 | + $this->logger->error('Error writing messages: ' . $exception->getMessage()); |
|
93 | 93 | throw new WriterException($exception->getMessage(), $exception->getCode()); |
94 | 94 | } |
95 | 95 | } |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | */ |
100 | 100 | protected function initialize() |
101 | 101 | { |
102 | - try{ |
|
103 | - $delayedQueue = self::DELAY_QUEUE_PREFIX.$this->delay.'Queue'; |
|
102 | + try { |
|
103 | + $delayedQueue = self::DELAY_QUEUE_PREFIX . $this->delay . 'Queue'; |
|
104 | 104 | |
105 | - $this->logger->info('Creating delayed exchange '.$this->delayedExchangeName); |
|
105 | + $this->logger->info('Creating delayed exchange ' . $this->delayedExchangeName); |
|
106 | 106 | // Delay Queue |
107 | 107 | $this->channel->exchange_declare($this->delayedExchangeName, 'fanout', false, true, true); |
108 | - $this->logger->info('Creating delayed queue '.$delayedQueue); |
|
108 | + $this->logger->info('Creating delayed queue ' . $delayedQueue); |
|
109 | 109 | $this->channel->queue_declare( |
110 | 110 | $delayedQueue, |
111 | 111 | false, |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | ] |
121 | 121 | ); |
122 | 122 | $this->channel->queue_bind($delayedQueue, $this->delayedExchangeName); |
123 | - } catch(\Exception $exception) { |
|
124 | - $this->logger->error('Error writing delayed messages: '.$exception->getMessage()); |
|
123 | + } catch (\Exception $exception) { |
|
124 | + $this->logger->error('Error writing delayed messages: ' . $exception->getMessage()); |
|
125 | 125 | throw new WriterException($exception->getMessage(), $exception->getCode()); |
126 | 126 | } |
127 | 127 | } |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | $this->initialize(); |
60 | 60 | try { |
61 | 61 | $messagesWithDelay = []; |
62 | - foreach($messages as $message) { |
|
63 | - if($message->getDelay() > 0) { |
|
62 | + foreach ($messages as $message) { |
|
63 | + if ($message->getDelay() > 0) { |
|
64 | 64 | $messagesWithDelay[$message->getDelay()][] = $message; |
65 | 65 | continue; |
66 | 66 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $this->channel->batch_basic_publish($msg, $this->exchangeConfig->getName(), $message->getName()); |
71 | 71 | } |
72 | 72 | $this->channel->publish_batch(); |
73 | - foreach($messagesWithDelay as $delay => $delayedMessages) { |
|
73 | + foreach ($messagesWithDelay as $delay => $delayedMessages) { |
|
74 | 74 | $delayedQueueWriter = new DelayedQueueWriter( |
75 | 75 | $this->exchangeConfig->getName(), |
76 | 76 | $delay, |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | ); |
80 | 80 | $delayedQueueWriter->write($delayedMessages); |
81 | 81 | } |
82 | - } catch(\Exception $exception) { |
|
83 | - $this->logger->error('Error writing messages: '.$exception->getMessage()); |
|
82 | + } catch (\Exception $exception) { |
|
83 | + $this->logger->error('Error writing messages: ' . $exception->getMessage()); |
|
84 | 84 | throw new WriterException($exception->getMessage(), $exception->getCode()); |
85 | 85 | } |
86 | 86 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | protected function initialize() |
92 | 92 | { |
93 | - if($this->channel) { |
|
93 | + if ($this->channel) { |
|
94 | 94 | return; |
95 | 95 | } |
96 | 96 | $this->logger->info('Connecting to RabbitMQ'); |
@@ -49,7 +49,7 @@ |
||
49 | 49 | $messageHandler->setCallback(array($this, 'notify')); |
50 | 50 | $queueReader = new QueueReader( |
51 | 51 | new AMQPLazyConnection($host, $port, $user, $password, $vHost), |
52 | - new QueueConfig(uniqid($queueName.'_', true), false, false, true, true), |
|
52 | + new QueueConfig(uniqid($queueName . '_', true), false, false, true, true), |
|
53 | 53 | new ExchangeConfig($exchangeName, 'topic', false, true, false), |
54 | 54 | $bindConfig, |
55 | 55 | new ConsumeConfig(false, false, true, false), |
@@ -21,7 +21,7 @@ |
||
21 | 21 | |
22 | 22 | public function consume(callable $callback) |
23 | 23 | { |
24 | - while(true) { |
|
24 | + while (true) { |
|
25 | 25 | $this->consumeOnce($callback); |
26 | 26 | } |
27 | 27 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | * @param array $body |
28 | 28 | * @param int $delay |
29 | 29 | */ |
30 | - public function __construct($name, array $body, $delay=0) |
|
30 | + public function __construct($name, array $body, $delay = 0) |
|
31 | 31 | { |
32 | 32 | $this->name = $name; |
33 | 33 | $this->body = $body; |
@@ -40,7 +40,7 @@ |
||
40 | 40 | */ |
41 | 41 | public function produce() |
42 | 42 | { |
43 | - if(!isset($this->tasks[0])) { |
|
43 | + if (!isset($this->tasks[0])) { |
|
44 | 44 | throw new TaskException('You must add at least 1 Task before producing.'); |
45 | 45 | } |
46 | 46 | $this->queueWriter->write($this->tasks); |