1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace BinaryCube\CarrotMQ\Support\Laravel\Console\Commands; |
6
|
|
|
|
7
|
|
|
use BinaryCube\CarrotMQ\Consumer; |
8
|
|
|
use BinaryCube\CarrotMQ\Extension; |
9
|
|
|
use Illuminate\Support\Facades\Log; |
|
|
|
|
10
|
|
|
|
11
|
|
|
use function intval; |
12
|
|
|
use function vsprintf; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class ConsumerCommand |
16
|
|
|
*/ |
17
|
|
|
class ConsumerCommand extends BaseCommand |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The name and signature of the console command. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $signature = ' |
26
|
|
|
carrot-mq:consume |
27
|
|
|
{consumer} |
28
|
|
|
{--message-limit=0 : Message Limit} |
29
|
|
|
{--idle-timeout=30 : Close gracefully when there are no incoming messages in the given time interval.}'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The console command description. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $description = 'Start consuming messages'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Execute the console command. |
40
|
|
|
* |
41
|
|
|
* @return integer |
42
|
|
|
* |
43
|
|
|
* @throws \Exception |
44
|
|
|
*/ |
45
|
|
|
public function handleInternal() |
46
|
|
|
{ |
47
|
|
|
$consumerId = (string) $this->input->getArgument('consumer'); |
48
|
|
|
|
49
|
|
|
if (! $this->carrot->container()->consumers()->has($consumerId)) { |
50
|
|
|
$this->error(vsprintf('Consumer "%s" not found.', [$consumerId])); |
51
|
|
|
return 0; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/* @var Consumer $consumer */ |
55
|
|
|
$consumer = $this->carrot->container()->consumers()->get($consumerId); |
56
|
|
|
|
57
|
|
|
$this->registerExtensions($consumer); |
58
|
|
|
|
59
|
|
|
$consumer->consume(); |
60
|
|
|
|
61
|
|
|
return 0; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param Consumer $consumer |
66
|
|
|
* |
67
|
|
|
* @return void |
68
|
|
|
*/ |
69
|
|
|
protected function registerExtensions(Consumer $consumer) |
70
|
|
|
{ |
71
|
|
|
$messageLimit = intval($this->input->getOption('message-limit')); |
72
|
|
|
$idleTimeout = intval($this->input->getOption('idle-timeout')); |
73
|
|
|
|
74
|
|
|
$extensions = [ |
75
|
|
|
new Extension\SignalExtension(), |
76
|
|
|
new Extension\IdleExtension($idleTimeout), |
77
|
|
|
]; |
78
|
|
|
|
79
|
|
|
if ($messageLimit > 0) { |
80
|
|
|
$extensions[] = new Extension\LimitConsumedMessagesExtension($messageLimit); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
foreach ($extensions as $extension) { |
84
|
|
|
/** |
85
|
|
|
* @var Extension\Extension $extension |
86
|
|
|
*/ |
87
|
|
|
$consumer->extensions()->put($extension::name(), $extension); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
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