1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace BinaryCube\CarrotMQ\Event\Consumer; |
6
|
|
|
|
7
|
|
|
use Interop\Queue\Context; |
8
|
|
|
use Interop\Queue\Message; |
9
|
|
|
use BinaryCube\CarrotMQ\Event\Event; |
10
|
|
|
use BinaryCube\CarrotMQ\Entity\Queue; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class AfterMessageReceived |
14
|
|
|
*/ |
15
|
|
|
class AfterMessageReceived extends Event |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var Queue |
20
|
|
|
*/ |
21
|
|
|
private $queue; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var Context |
25
|
|
|
*/ |
26
|
|
|
private $context; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var Message |
30
|
|
|
*/ |
31
|
|
|
private $message; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var float |
35
|
|
|
*/ |
36
|
|
|
private $receivedAt; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
private $result; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var boolean |
45
|
|
|
*/ |
46
|
|
|
private $executionInterrupted; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var integer |
50
|
|
|
*/ |
51
|
|
|
private $exitStatus; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
public static function name(): string |
57
|
|
|
{ |
58
|
|
|
return 'consumer.event.after.message.received'; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Constructor. |
63
|
|
|
* |
64
|
|
|
* @param Queue $queue |
65
|
|
|
* @param Context $context |
66
|
|
|
* @param Message $message |
67
|
|
|
* @param float $receivedAt |
68
|
|
|
* @param string $result |
69
|
|
|
*/ |
70
|
|
|
public function __construct( |
71
|
|
|
Queue $queue, |
72
|
|
|
Context $context, |
73
|
|
|
Message $message, |
74
|
|
|
float $receivedAt, |
75
|
|
|
string $result |
76
|
|
|
) { |
77
|
|
|
$this->queue = $queue; |
78
|
|
|
$this->context = $context; |
79
|
|
|
$this->message = $message; |
80
|
|
|
$this->receivedAt = $receivedAt; |
81
|
|
|
$this->result = $result; |
82
|
|
|
$this->executionInterrupted = false; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return Queue |
87
|
|
|
*/ |
88
|
|
|
public function queue(): Queue |
89
|
|
|
{ |
90
|
|
|
return $this->queue; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return Context |
95
|
|
|
*/ |
96
|
|
|
public function context(): Context |
97
|
|
|
{ |
98
|
|
|
return $this->context; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return Message |
103
|
|
|
*/ |
104
|
|
|
public function message(): Message |
105
|
|
|
{ |
106
|
|
|
return $this->message; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return float |
111
|
|
|
*/ |
112
|
|
|
public function receivedAt(): float |
113
|
|
|
{ |
114
|
|
|
return $this->receivedAt; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
|
|
public function result(): string |
121
|
|
|
{ |
122
|
|
|
return $this->result; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return int|null |
127
|
|
|
*/ |
128
|
|
|
public function exitStatus(): ?int |
129
|
|
|
{ |
130
|
|
|
return $this->exitStatus; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return bool |
135
|
|
|
*/ |
136
|
|
|
public function isExecutionInterrupted(): bool |
137
|
|
|
{ |
138
|
|
|
return $this->executionInterrupted; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param int|null $exitStatus |
143
|
|
|
* |
144
|
|
|
* @return void; |
145
|
|
|
*/ |
146
|
|
|
public function interruptExecution(?int $exitStatus = null): void |
147
|
|
|
{ |
148
|
|
|
$this->exitStatus = $exitStatus; |
149
|
|
|
$this->executionInterrupted = true; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
} |
153
|
|
|
|