-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathConsumer.php
More file actions
252 lines (217 loc) · 5.47 KB
/
Consumer.php
File metadata and controls
252 lines (217 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<?php
declare(strict_types=1);
namespace RabbitMqModule\Options;
use InvalidArgumentException;
use function is_array;
/**
* @psalm-import-type ExchangeOptions from Exchange
* @psalm-import-type QueueOptions from Queue
* @psalm-import-type QosOptions from Qos
*
* @psalm-type ConsumerOptions = array{
* description?: string,
* connection?: string,
* queue: QueueOptions|Queue,
* exchange?: ExchangeOptions|Exchange,
* callback: string|callable(\PhpAmqpLib\Message\AMQPMessage): (int|null),
* idleTimeout?: int,
* consumerTag?: string,
* qos?: QosOptions,
* auto_setup_fabric_enabled?: bool,
* signals_enabled?: bool,
* }
*/
class Consumer extends AbstractOptions
{
protected string $connection = 'default';
protected ?Exchange $exchange = null;
protected ?Queue $queue = null;
/** @var null|string|callable(\PhpAmqpLib\Message\AMQPMessage): (int|null) */
protected $callback;
protected int $idleTimeout = 0;
protected ?string $consumerTag = null;
protected ?Qos $qos = null;
protected bool $autoSetupFabricEnabled = true;
protected bool $signalsEnabled = true;
protected string $description = '';
/**
* @psalm-param ConsumerOptions $data
*/
public static function fromArray(array $data): self
{
return new self($data);
}
public function getConnection(): string
{
return $this->connection;
}
/**
* @internal
*
* @psalm-internal RabbitMqModule
*/
public function setConnection(string $connection): void
{
$this->connection = $connection;
}
/**
* @return Exchange
*/
public function getExchange(): ?Exchange
{
return $this->exchange;
}
/**
* @internal
*
* @psalm-internal RabbitMqModule
*
* @param array<string, mixed>|Exchange $exchange
*
* @throws InvalidArgumentException
*/
public function setExchange($exchange): void
{
if (is_array($exchange)) {
$exchange = new Exchange($exchange);
}
if (! $exchange instanceof Exchange) {
throw new InvalidArgumentException(
'Parameter "exchange" should be array or an instance of Exchange options'
);
}
$this->exchange = $exchange;
}
public function getQueue(): Queue
{
if (! $this->queue) {
throw new \RuntimeException('No queue configuration for consumer');
}
return $this->queue;
}
/**
* @internal
*
* @psalm-internal RabbitMqModule
*
* @param array<string, mixed>|Queue $queue
*
* @throws InvalidArgumentException
*/
public function setQueue($queue): void
{
if (is_array($queue)) {
$queue = new Queue($queue);
}
if (! $queue instanceof Queue) {
throw new InvalidArgumentException('Parameter "queue" should be array or an instance of Queue options');
}
$this->queue = $queue;
}
/**
* @return null|string|(callable(\PhpAmqpLib\Message\AMQPMessage): (int|null))
*/
public function getCallback()
{
return $this->callback;
}
/**
* @internal
*
* @psalm-internal RabbitMqModule
*
* @param null|string|callable(\PhpAmqpLib\Message\AMQPMessage): (int|null) $callback
*/
public function setCallback($callback): void
{
$this->callback = $callback;
}
public function getIdleTimeout(): int
{
return $this->idleTimeout;
}
/**
* @internal
*
* @psalm-internal RabbitMqModule
*/
public function setIdleTimeout(int $idleTimeout): void
{
$this->idleTimeout = $idleTimeout;
}
public function getConsumerTag(): ?string
{
return $this->consumerTag;
}
/**
* @internal
*
* @psalm-internal RabbitMqModule
*/
public function setConsumerTag(string $consumerTag): void
{
$this->consumerTag = $consumerTag;
}
public function getQos(): ?Qos
{
return $this->qos;
}
/**
* @internal
*
* @psalm-internal RabbitMqModule
*
* @param Qos|array<string, mixed> $qos
*
* @throws InvalidArgumentException
*/
public function setQos($qos): void
{
if (is_array($qos)) {
$qos = new Qos($qos);
}
if (! $qos instanceof Qos) {
throw new InvalidArgumentException('Parameter "qos" should be array or an instance of Qos options');
}
$this->qos = $qos;
}
public function isAutoSetupFabricEnabled(): bool
{
return $this->autoSetupFabricEnabled;
}
/**
* @internal
*
* @psalm-internal RabbitMqModule
*/
public function setAutoSetupFabricEnabled(bool $autoSetupFabricEnabled): void
{
$this->autoSetupFabricEnabled = $autoSetupFabricEnabled;
}
public function isSignalsEnabled(): bool
{
return $this->signalsEnabled;
}
/**
* @internal
*
* @psalm-internal RabbitMqModule
*/
public function setSignalsEnabled(bool $signalsEnabled): void
{
$this->signalsEnabled = $signalsEnabled;
}
public function getDescription(): string
{
return $this->description;
}
/**
* @internal
*
* @psalm-internal RabbitMqModule
*/
public function setDescription(string $description): void
{
$this->description = $description;
}
}