1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunnu\RabbitMQ; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
6
|
|
|
use PhpAmqpLib\Channel\AMQPChannel; |
7
|
|
|
|
8
|
|
|
class RabbitMQDelivery |
9
|
|
|
{ |
10
|
|
|
protected Collection $config; |
11
|
|
|
|
12
|
|
|
public function __construct(array $config = []) |
13
|
|
|
{ |
14
|
|
|
$this->setConfig($config); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @return Collection |
19
|
|
|
*/ |
20
|
|
|
public function getConfig(): Collection |
21
|
|
|
{ |
22
|
|
|
return $this->config; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param array $config |
27
|
|
|
* |
28
|
|
|
* @return \Anik\Amqp\Delivery |
|
|
|
|
29
|
|
|
*/ |
30
|
|
|
public function setConfig(array $config): self |
31
|
|
|
{ |
32
|
|
|
$this->config = new Collection($config); |
33
|
|
|
|
34
|
|
|
return $this; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Acknowledge a message. |
39
|
|
|
* |
40
|
|
|
* @throws RabbitMQException |
41
|
|
|
* @return bool |
42
|
|
|
* |
43
|
|
|
*/ |
44
|
|
|
public function acknowledge(): bool |
45
|
|
|
{ |
46
|
|
|
$config = $this->getConfig(); |
47
|
|
|
$info = $config->get('delivery_info', []); |
48
|
|
|
/** |
49
|
|
|
* @var AMQPChannel |
50
|
|
|
*/ |
51
|
|
|
$channel = $info['channel'] ?? null; |
52
|
|
|
|
53
|
|
|
if (!$channel) { |
54
|
|
|
throw new RabbitMQException('Delivery info or channel is not set'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$channel->basic_ack( |
58
|
|
|
$info['delivery_tag'] ?? null |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
if ($config->get('body') === 'quit') { |
62
|
|
|
$channel->basic_cancel( |
63
|
|
|
$info['consumer_tag'] ?? null |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return true; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Rejects message w/ requeue. |
72
|
|
|
* |
73
|
|
|
* @param bool $requeue |
74
|
|
|
* |
75
|
|
|
* @throws RabbitMQException |
76
|
|
|
* @return bool |
77
|
|
|
* |
78
|
|
|
*/ |
79
|
|
|
public function reject($requeue = false): bool |
80
|
|
|
{ |
81
|
|
|
$config = $this->getConfig(); |
82
|
|
|
$info = $config->get('delivery_info'); |
83
|
|
|
/** |
84
|
|
|
* @var AMQPChannel |
85
|
|
|
*/ |
86
|
|
|
$channel = $info['channel'] ?? null; |
87
|
|
|
|
88
|
|
|
if (!$channel) { |
89
|
|
|
throw new RabbitMQException('Delivery info or channel is not set'); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$channel->basic_reject( |
93
|
|
|
$info['delivery_tag'] ?? null, |
94
|
|
|
$requeue |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
return true; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
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