|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MyOnlineStore\Bundle\RabbitMqManagerBundle\Configuration\Consumer; |
|
4
|
|
|
|
|
5
|
|
|
use MyOnlineStore\Bundle\RabbitMqManagerBundle\Configuration\Section\SectionCollection; |
|
6
|
|
|
|
|
7
|
|
|
final class ConsumerConfiguration |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var ConsumerSectionFactoryInterface |
|
11
|
|
|
*/ |
|
12
|
|
|
private $sectionFactory; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
private $path; |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @param ConsumerSectionFactoryInterface $sectionFactory |
|
22
|
|
|
* @param string $path |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct(ConsumerSectionFactoryInterface $sectionFactory, $path) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->sectionFactory = $sectionFactory; |
|
27
|
|
|
$this->path = $path; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param array $consumer |
|
32
|
|
|
* @param null|string $route |
|
33
|
|
|
* |
|
34
|
|
|
* @return SectionCollection |
|
35
|
|
|
*/ |
|
36
|
|
|
public function generate(array $consumer, $route = null) |
|
37
|
|
|
{ |
|
38
|
|
|
$sections = new SectionCollection(); |
|
39
|
|
|
|
|
40
|
|
|
$sections->addSection( |
|
41
|
|
|
$this->sectionFactory->createRabbitmq( |
|
42
|
|
|
[ |
|
43
|
|
|
'host' => $consumer['connection']['host'], |
|
44
|
|
|
'username' => $consumer['connection']['user'], |
|
45
|
|
|
'password' => $consumer['connection']['password'], |
|
46
|
|
|
'vhost' => $consumer['connection']['vhost'], |
|
47
|
|
|
'port' => $consumer['connection']['port'], |
|
48
|
|
|
'queue' => $consumer['worker']['queue']['name'], |
|
49
|
|
|
'compression' => $consumer['worker']['compression'], |
|
50
|
|
|
] |
|
51
|
|
|
) |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
if ($consumer['worker']['prefetch']['count'] > 0) { |
|
55
|
|
|
$sections->addSection( |
|
56
|
|
|
$this->sectionFactory->createPrefetch( |
|
57
|
|
|
[ |
|
58
|
|
|
'count' => $consumer['worker']['prefetch']['count'], |
|
59
|
|
|
'global' => $consumer['worker']['prefetch']['global'], |
|
60
|
|
|
] |
|
61
|
|
|
) |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if (isset($consumer['worker']['exchange'])) { |
|
66
|
|
|
$sections->addSection( |
|
67
|
|
|
$this->sectionFactory->createExchange( |
|
68
|
|
|
[ |
|
69
|
|
|
'name' => $consumer['worker']['exchange']['name'], |
|
70
|
|
|
'type' => $consumer['worker']['exchange']['type'], |
|
71
|
|
|
'durable' => $consumer['worker']['exchange']['durable'], |
|
72
|
|
|
'autodelete' => $consumer['worker']['exchange']['autodelete'], |
|
73
|
|
|
] |
|
74
|
|
|
) |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if (isset($consumer['worker']['exchange'])) { |
|
79
|
|
|
$sections->addSection( |
|
80
|
|
|
$this->sectionFactory->createExchange( |
|
81
|
|
|
[ |
|
82
|
|
|
'name' => $consumer['worker']['exchange']['name'], |
|
83
|
|
|
'type' => $consumer['worker']['exchange']['type'], |
|
84
|
|
|
'durable' => $consumer['worker']['exchange']['durable'], |
|
85
|
|
|
'autodelete' => $consumer['worker']['exchange']['autodelete'], |
|
86
|
|
|
] |
|
87
|
|
|
) |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if (null !== $route) { |
|
92
|
|
|
$sections->addSection( |
|
93
|
|
|
$this->sectionFactory->createQueue( |
|
94
|
|
|
[ |
|
95
|
|
|
'routingkey' => $route, |
|
96
|
|
|
] |
|
97
|
|
|
) |
|
98
|
|
|
); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
$sections->addSection( |
|
102
|
|
|
$this->sectionFactory->createLogs( |
|
103
|
|
|
[ |
|
104
|
|
|
'info' => sprintf('%s/consumer.log', $this->path), |
|
105
|
|
|
'error' => sprintf('%s/consumer.err', $this->path), |
|
106
|
|
|
] |
|
107
|
|
|
) |
|
108
|
|
|
); |
|
109
|
|
|
|
|
110
|
|
|
return $sections; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|