1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: quimmanrique |
5
|
|
|
* Date: 13/02/17 |
6
|
|
|
* Time: 18:55 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Cmp\Queues\Infrastructure\AmqpLib\v26\RabbitMQ\Task; |
10
|
|
|
|
11
|
|
|
use Cmp\Queues\Domain\Task\Consumer as DomainConsumer; |
12
|
|
|
use Cmp\Queues\Domain\Task\JSONTaskFactory; |
13
|
|
|
use Cmp\Queues\Infrastructure\AmqpLib\v26\RabbitMQ\Queue\Config\BindConfig; |
14
|
|
|
use Cmp\Queues\Infrastructure\AmqpLib\v26\RabbitMQ\Queue\Config\ConsumeConfig; |
15
|
|
|
use Cmp\Queues\Infrastructure\AmqpLib\v26\RabbitMQ\Queue\Config\ExchangeConfig; |
16
|
|
|
use Cmp\Queues\Infrastructure\AmqpLib\v26\RabbitMQ\Queue\Config\QueueConfig; |
17
|
|
|
use Cmp\Queues\Infrastructure\AmqpLib\v26\RabbitMQ\Queue\MessageHandler; |
18
|
|
|
use Cmp\Queues\Infrastructure\AmqpLib\v26\RabbitMQ\Queue\QueueReader; |
19
|
|
|
use PhpAmqpLib\Connection\AMQPLazyConnection; |
20
|
|
|
use Psr\Log\LoggerInterface; |
21
|
|
|
|
22
|
|
View Code Duplication |
class Consumer extends DomainConsumer |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Consumer constructor. |
26
|
|
|
* @param string $host |
27
|
|
|
* @param int $port |
28
|
|
|
* @param string $user |
29
|
|
|
* @param string $password |
30
|
|
|
* @param string $vHost |
31
|
|
|
* @param string $exchangeName |
32
|
|
|
* @param string $queueName |
33
|
|
|
* @param LoggerInterface $logger |
34
|
|
|
*/ |
35
|
|
|
public function __construct( |
36
|
|
|
$host, |
37
|
|
|
$port, |
38
|
|
|
$user, |
39
|
|
|
$password, |
40
|
|
|
$vHost, |
41
|
|
|
$exchangeName, |
42
|
|
|
$queueName, |
43
|
|
|
LoggerInterface $logger |
44
|
|
|
) |
45
|
|
|
{ |
46
|
|
|
$queueReader = new QueueReader( |
47
|
|
|
new AMQPLazyConnection($host, $port, $user, $password, $vHost), |
48
|
|
|
new QueueConfig($queueName, false, true, false, false), |
49
|
|
|
new ExchangeConfig($exchangeName, 'fanout', false, true, false), |
50
|
|
|
new BindConfig(), |
51
|
|
|
new ConsumeConfig(false, false, false, false), |
52
|
|
|
new MessageHandler(new JSONTaskFactory()), |
53
|
|
|
$logger |
54
|
|
|
); |
55
|
|
|
parent::__construct($queueReader); |
56
|
|
|
} |
57
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.