1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cmobi\RabbitmqBundle\Transport\Worker; |
4
|
|
|
|
5
|
|
|
use Cmobi\RabbitmqBundle\Connection\ConnectionManager; |
6
|
|
|
use Cmobi\RabbitmqBundle\Connection\Exception\InvalidAMQPChannelException; |
7
|
|
|
use Cmobi\RabbitmqBundle\Queue\Queue; |
8
|
|
|
use Cmobi\RabbitmqBundle\Queue\QueueBuilderInterface; |
9
|
|
|
use Cmobi\RabbitmqBundle\Queue\QueueServiceInterface; |
10
|
|
|
use Psr\Log\LoggerInterface; |
11
|
|
|
|
12
|
|
View Code Duplication |
class WorkerBuilder implements QueueBuilderInterface |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
private $connectionManager; |
15
|
|
|
private $logger; |
16
|
|
|
private $parameters; |
17
|
|
|
|
18
|
|
|
public function __construct(ConnectionManager $connManager, LoggerInterface $logger, array $parameters) |
19
|
|
|
{ |
20
|
|
|
$this->connectionManager = $connManager; |
21
|
|
|
$this->logger = $logger; |
22
|
|
|
$this->parameters = $parameters; |
23
|
|
|
$this->channel = null; |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param $queueName |
28
|
|
|
* @param QueueServiceInterface $queueService |
29
|
|
|
* |
30
|
|
|
* @return Queue |
31
|
|
|
* |
32
|
|
|
* @throws InvalidAMQPChannelException |
33
|
|
|
*/ |
34
|
|
|
public function buildQueue($queueName, QueueServiceInterface $queueService) |
35
|
|
|
{ |
36
|
|
|
$qos = 1; |
37
|
|
|
|
38
|
|
|
if (array_key_exists('cmobi_rabbitmq.basic_qos', $this->parameters)) { |
39
|
|
|
$qos = $this->parameters['cmobi_rabbitmq.basic_qos']; |
40
|
|
|
} |
41
|
|
|
$rpcQueueBag = new WorkerQueueBag($queueName, $qos); |
42
|
|
|
|
43
|
|
|
$queue = new Queue($this->getConnectionManager(), $rpcQueueBag, $this->logger); |
44
|
|
|
$queueCallback = new WorkerQueueCallback($queueService); |
45
|
|
|
$queue->setCallback($queueCallback); |
46
|
|
|
|
47
|
|
|
return $queue; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return ConnectionManager |
52
|
|
|
*/ |
53
|
|
|
public function getConnectionManager() |
54
|
|
|
{ |
55
|
|
|
return $this->connectionManager; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return string|false |
60
|
|
|
*/ |
61
|
|
|
public function getExchangeName() |
62
|
|
|
{ |
63
|
|
|
return false; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return string|false |
68
|
|
|
*/ |
69
|
|
|
public function getExchangeType() |
70
|
|
|
{ |
71
|
|
|
return false; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
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.