1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OldSound\RabbitMqBundle\ReceiverExecutor; |
4
|
|
|
|
5
|
|
|
use OldSound\RabbitMqBundle\Event\AfterProcessingMessagesEvent; |
6
|
|
|
use OldSound\RabbitMqBundle\Event\BeforeProcessingMessagesEvent; |
7
|
|
|
use OldSound\RabbitMqBundle\Logger\ExtraContextLogger; |
8
|
|
|
use OldSound\RabbitMqBundle\RabbitMq\Consuming; |
9
|
|
|
|
10
|
|
|
class ReceiverExecutorDecorator implements ReceiverExecutorInterface |
11
|
|
|
{ |
12
|
|
|
/** @var Consuming */ |
13
|
|
|
private $consuming; |
14
|
|
|
|
15
|
|
|
/** @var LoggerInterface */ |
|
|
|
|
16
|
|
|
private $logger; |
17
|
|
|
|
18
|
|
|
public function __construct(Consuming $consuming, LoggerInterface $logger) |
19
|
|
|
{ |
20
|
|
|
$this->consuming = $consuming; |
21
|
|
|
$this->logger = $logger; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
private function createLoggerExtraContext(array $messages) |
25
|
|
|
{ |
26
|
|
|
$amqpContext = ['queue' => $this->consuming->options->queue]; |
27
|
|
|
if ($this->consuming->executeReceiverStrategy->canPrecessMultiMessages()) { |
28
|
|
|
$amqpContext['messages'] = $messages; |
29
|
|
|
} else { |
30
|
|
|
if (count($messages) > 1) { |
31
|
|
|
// TODO |
32
|
|
|
} |
33
|
|
|
$amqpContext['message'] = $messages[0]; |
34
|
|
|
} |
35
|
|
|
return $amqpContext; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function execute(array $messages, $receiver): array |
39
|
|
|
{ |
40
|
|
|
$logger = new ExtraContextLogger($this->logger, ['amqp' => $this->createLoggerExtraContext($messages)]); |
41
|
|
|
|
42
|
|
|
$event = new BeforeProcessingMessagesEvent($messages, $this->consuming->options); |
43
|
|
|
$this->dispatchEvent(BeforeProcessingMessagesEvent::NAME, $event); |
|
|
|
|
44
|
|
|
if ($event->isStoppingConsumer()) { |
45
|
|
|
throw new StopConsumerException(); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
try { |
49
|
|
|
$flags = $this->consuming->receiverExecutor->execute($messages, $receiver); |
50
|
|
|
} catch (Exception\StopConsumerException $e) { |
|
|
|
|
51
|
|
|
$logger->info('Consumer requested stop', [ |
52
|
|
|
'exception' => $e |
53
|
|
|
]); |
54
|
|
|
|
55
|
|
|
throw $e; |
56
|
|
|
} catch (\Throwable $e) { |
57
|
|
|
$logger->error('Throw exception while process messages', [ |
58
|
|
|
'exception' => $e |
59
|
|
|
]); |
60
|
|
|
throw $e; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
$logger->info('Queue messages processed'); // TODO add flag code |
65
|
|
|
$event = new AfterProcessingMessagesEvent($this, $messages); // TODO add flag code |
|
|
|
|
66
|
|
|
$this->dispatchEvent(AfterProcessingMessagesEvent::NAME, $event); |
67
|
|
|
if ($event->isStoppingConsumer()) { |
68
|
|
|
throw new StopConsumerException(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $flags; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function support($receiver): bool |
75
|
|
|
{ |
76
|
|
|
return $this->consuming->receiverExecutor->support($receiver); |
77
|
|
|
} |
78
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths