1 | <?php |
||
14 | class Consumer implements EventSubscriberInterface |
||
15 | { |
||
16 | /** |
||
17 | * @var ConsumerInterface |
||
18 | */ |
||
19 | private $consumer; |
||
20 | |||
21 | /** |
||
22 | * @var OutputInterface |
||
23 | */ |
||
24 | private $output; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $consumerTag; |
||
30 | |||
31 | /** |
||
32 | * @var LimiterInterface[] |
||
33 | */ |
||
34 | private $limiters = []; |
||
35 | |||
36 | /** |
||
37 | * @var int |
||
38 | */ |
||
39 | private $startTime; |
||
40 | |||
41 | /** |
||
42 | * @var int |
||
43 | */ |
||
44 | private $minDuration = 15; |
||
45 | |||
46 | /** |
||
47 | * @var int |
||
48 | */ |
||
49 | private $processed = 0; |
||
50 | |||
51 | /** |
||
52 | * @var int |
||
53 | */ |
||
54 | private $batchSize = 25; |
||
55 | |||
56 | /** |
||
57 | * @var int |
||
58 | */ |
||
59 | private $coolDownTime = 0; |
||
60 | |||
61 | /** |
||
62 | * @param ConsumerInterface $consumer |
||
63 | * @param OutputInterface $output |
||
64 | * @param string $consumerTag |
||
65 | */ |
||
66 | public function __construct(ConsumerInterface $consumer, OutputInterface $output, $consumerTag = null) |
||
74 | |||
75 | /** |
||
76 | * @inheritdoc |
||
77 | */ |
||
78 | public static function getSubscribedEvents() |
||
86 | |||
87 | /** |
||
88 | * @param LimiterInterface $limiter |
||
89 | */ |
||
90 | public function addLimiter(LimiterInterface $limiter) |
||
94 | |||
95 | /** |
||
96 | * @param int $duration |
||
97 | * |
||
98 | * @return $this |
||
99 | */ |
||
100 | public function mustRunFor($duration) |
||
106 | |||
107 | /** |
||
108 | * @param int $batchSize |
||
109 | * |
||
110 | * @return $this |
||
111 | */ |
||
112 | public function flushAfter($batchSize) |
||
118 | |||
119 | /** |
||
120 | * @param int $coolDownTime |
||
121 | * |
||
122 | * @return $this |
||
123 | */ |
||
124 | public function waitBetweenMessages($coolDownTime) |
||
130 | |||
131 | /** |
||
132 | * @return int |
||
133 | */ |
||
134 | public function getProcessed() |
||
138 | |||
139 | /** |
||
140 | * @return int |
||
141 | */ |
||
142 | public function getStartTime() |
||
146 | |||
147 | /** |
||
148 | * @return int |
||
149 | */ |
||
150 | public function getDuration() |
||
154 | |||
155 | /** |
||
156 | * @throws \Exception |
||
157 | */ |
||
158 | public function consume() |
||
177 | |||
178 | /** |
||
179 | * @param ConsumeEvent $event |
||
180 | */ |
||
181 | public function onConsumeMessage(ConsumeEvent $event) |
||
194 | |||
195 | /** |
||
196 | * @param ConsumeEvent $event |
||
197 | */ |
||
198 | public function onMessageConsumed(ConsumeEvent $event) |
||
231 | |||
232 | /** |
||
233 | * @param ConsumeExceptionEvent $event |
||
234 | */ |
||
235 | public function onConsumeException(ConsumeExceptionEvent $event) |
||
249 | |||
250 | /** |
||
251 | * @param string $payload |
||
252 | * @param bool $fullPayload |
||
253 | * |
||
254 | * @return string |
||
255 | */ |
||
256 | private function getPayloadOutput($payload, $fullPayload = false) |
||
269 | |||
270 | /** |
||
271 | * Dispatches flush event. |
||
272 | */ |
||
273 | private function flush() |
||
282 | |||
283 | /** |
||
284 | * Shutdown procedure |
||
285 | */ |
||
286 | private function shutdown() |
||
310 | } |
||
311 |