Total Complexity | 6 |
Total Lines | 50 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
8 | class TaskQueue |
||
9 | { |
||
10 | private $connection; |
||
11 | private $channel; |
||
12 | |||
13 | public function __construct() |
||
14 | { |
||
15 | $this->connection = $this->getConnection(); |
||
16 | $this->channel = $this->queueChannel(); |
||
17 | } |
||
18 | |||
19 | public function add(Task $task) |
||
20 | { |
||
21 | $message = $this->makeMessage($task); |
||
22 | $this->channel->basic_publish($message, '', config('rabbitmq.routing_key')); |
||
23 | } |
||
24 | |||
25 | public function close() |
||
26 | { |
||
27 | $this->channel->close(); |
||
28 | $this->connection->close(); |
||
29 | } |
||
30 | |||
31 | private function getConnection() |
||
39 | ); |
||
40 | } |
||
41 | |||
42 | private function queueChannel() |
||
43 | { |
||
44 | $channel = $this->connection->channel(); |
||
45 | $channel->queue_declare(config('rabbitmq.queue'), false, true); |
||
46 | |||
47 | return $channel; |
||
48 | } |
||
49 | |||
50 | private function makeMessage(Task $task) |
||
58 | } |
||
59 | } |
||
60 |