1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mouf\AmqpClient\Objects; |
4
|
|
|
|
5
|
|
|
use PhpAmqpLib\Message\AMQPMessage; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* A message sent to RabbitMQ. |
9
|
|
|
* |
10
|
|
|
* Note: by default, those message are set to "persistent delivery mode" |
11
|
|
|
*/ |
12
|
|
|
class Message |
13
|
|
|
{ |
14
|
|
|
private $body; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private $content_type; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $content_encoding; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
private $application_headers; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var int |
33
|
|
|
*/ |
34
|
|
|
private $delivery_mode = AMQPMessage::DELIVERY_MODE_PERSISTENT; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var int |
38
|
|
|
*/ |
39
|
|
|
private $priority; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
private $correlation_id; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
private $reply_to; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
private $expiration; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var string |
58
|
|
|
*/ |
59
|
|
|
private $message_id; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var \DateTimeInterface |
63
|
|
|
*/ |
64
|
|
|
private $timestamp; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var string |
68
|
|
|
*/ |
69
|
|
|
private $type; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var string |
73
|
|
|
*/ |
74
|
|
|
private $user_id; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var string |
78
|
|
|
*/ |
79
|
|
|
private $app_id; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var string |
83
|
|
|
*/ |
84
|
|
|
private $cluster_id; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Message constructor. |
88
|
|
|
* |
89
|
|
|
* @param string $body |
90
|
|
|
*/ |
91
|
|
|
public function __construct($body) |
92
|
|
|
{ |
93
|
|
|
$this->body = $body; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
public function getBody() |
100
|
|
|
{ |
101
|
|
|
return $this->body; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return string |
106
|
|
|
*/ |
107
|
|
|
public function getContentType() |
108
|
|
|
{ |
109
|
|
|
return $this->content_type; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param string $content_type |
114
|
|
|
* @return Message |
115
|
|
|
*/ |
116
|
|
|
public function setContentType($content_type) |
117
|
|
|
{ |
118
|
|
|
$this->content_type = $content_type; |
119
|
|
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
|
|
public function getContentEncoding() |
126
|
|
|
{ |
127
|
|
|
return $this->content_encoding; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param string $content_encoding |
132
|
|
|
* @return Message |
133
|
|
|
*/ |
134
|
|
|
public function setContentEncoding($content_encoding) |
135
|
|
|
{ |
136
|
|
|
$this->content_encoding = $content_encoding; |
137
|
|
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return array |
142
|
|
|
*/ |
143
|
|
|
public function getApplicationHeaders() |
144
|
|
|
{ |
145
|
|
|
return $this->application_headers; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param array $application_headers |
150
|
|
|
* @return Message |
151
|
|
|
*/ |
152
|
|
|
public function setApplicationHeaders($application_headers) |
153
|
|
|
{ |
154
|
|
|
$this->application_headers = $application_headers; |
155
|
|
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @return int |
160
|
|
|
*/ |
161
|
|
|
public function getDeliveryMode() |
162
|
|
|
{ |
163
|
|
|
return $this->delivery_mode; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param int $delivery_mode |
168
|
|
|
* @return Message |
169
|
|
|
*/ |
170
|
|
|
public function setDeliveryMode($delivery_mode) |
171
|
|
|
{ |
172
|
|
|
$this->delivery_mode = $delivery_mode; |
173
|
|
|
return $this; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @return int |
178
|
|
|
*/ |
179
|
|
|
public function getPriority() |
180
|
|
|
{ |
181
|
|
|
return $this->priority; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @param int $priority |
186
|
|
|
* @return Message |
187
|
|
|
*/ |
188
|
|
|
public function setPriority($priority) |
189
|
|
|
{ |
190
|
|
|
$this->priority = $priority; |
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @return string |
196
|
|
|
*/ |
197
|
|
|
public function getCorrelationId() |
198
|
|
|
{ |
199
|
|
|
return $this->correlation_id; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @param string $correlation_id |
204
|
|
|
* @return Message |
205
|
|
|
*/ |
206
|
|
|
public function setCorrelationId($correlation_id) |
207
|
|
|
{ |
208
|
|
|
$this->correlation_id = $correlation_id; |
209
|
|
|
return $this; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @return string |
214
|
|
|
*/ |
215
|
|
|
public function getReplyTo() |
216
|
|
|
{ |
217
|
|
|
return $this->reply_to; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @param string $reply_to |
222
|
|
|
* @return Message |
223
|
|
|
*/ |
224
|
|
|
public function setReplyTo($reply_to) |
225
|
|
|
{ |
226
|
|
|
$this->reply_to = $reply_to; |
227
|
|
|
return $this; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @return string |
232
|
|
|
*/ |
233
|
|
|
public function getExpiration() |
234
|
|
|
{ |
235
|
|
|
return $this->expiration; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param string $expiration |
240
|
|
|
* @return Message |
241
|
|
|
*/ |
242
|
|
|
public function setExpiration($expiration) |
243
|
|
|
{ |
244
|
|
|
$this->expiration = $expiration; |
245
|
|
|
return $this; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @return string |
250
|
|
|
*/ |
251
|
|
|
public function getMessageId() |
252
|
|
|
{ |
253
|
|
|
return $this->message_id; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* @param string $message_id |
258
|
|
|
* @return Message |
259
|
|
|
*/ |
260
|
|
|
public function setMessageId($message_id) |
261
|
|
|
{ |
262
|
|
|
$this->message_id = $message_id; |
263
|
|
|
return $this; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @return \DateTimeInterface |
268
|
|
|
*/ |
269
|
|
|
public function getTimestamp() |
270
|
|
|
{ |
271
|
|
|
return $this->timestamp; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @param \DateTimeInterface $timestamp |
276
|
|
|
* @return Message |
277
|
|
|
*/ |
278
|
|
|
public function setTimestamp($timestamp) |
279
|
|
|
{ |
280
|
|
|
$this->timestamp = $timestamp; |
281
|
|
|
return $this; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @return string |
286
|
|
|
*/ |
287
|
|
|
public function getType() |
288
|
|
|
{ |
289
|
|
|
return $this->type; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* @param string $type |
294
|
|
|
* @return Message |
295
|
|
|
*/ |
296
|
|
|
public function setType($type) |
297
|
|
|
{ |
298
|
|
|
$this->type = $type; |
299
|
|
|
return $this; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* @return string |
304
|
|
|
*/ |
305
|
|
|
public function getUserId() |
306
|
|
|
{ |
307
|
|
|
return $this->user_id; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* @param string $user_id |
312
|
|
|
* @return Message |
313
|
|
|
*/ |
314
|
|
|
public function setUserId($user_id) |
315
|
|
|
{ |
316
|
|
|
$this->user_id = $user_id; |
317
|
|
|
return $this; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* @return string |
322
|
|
|
*/ |
323
|
|
|
public function getAppId() |
324
|
|
|
{ |
325
|
|
|
return $this->app_id; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* @param string $app_id |
330
|
|
|
* @return Message |
331
|
|
|
*/ |
332
|
|
|
public function setAppId($app_id) |
333
|
|
|
{ |
334
|
|
|
$this->app_id = $app_id; |
335
|
|
|
return $this; |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* @return string |
340
|
|
|
*/ |
341
|
|
|
public function getClusterId() |
342
|
|
|
{ |
343
|
|
|
return $this->cluster_id; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* @param string $cluster_id |
348
|
|
|
* @return Message |
349
|
|
|
*/ |
350
|
|
|
public function setClusterId($cluster_id) |
351
|
|
|
{ |
352
|
|
|
$this->cluster_id = $cluster_id; |
353
|
|
|
return $this; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* @return AMQPMessage |
358
|
|
|
*/ |
359
|
|
|
public function toAMQPMessage() |
360
|
|
|
{ |
361
|
|
|
$parameters = []; |
362
|
|
|
$this->fillParameters('content_type', $parameters); |
363
|
|
|
$this->fillParameters('content_encoding', $parameters); |
364
|
|
|
$this->fillParameters('application_headers', $parameters); |
365
|
|
|
$this->fillParameters('delivery_mode', $parameters); |
366
|
|
|
$this->fillParameters('priority', $parameters); |
367
|
|
|
$this->fillParameters('correlation_id', $parameters); |
368
|
|
|
$this->fillParameters('reply_to', $parameters); |
369
|
|
|
$this->fillParameters('expiration', $parameters); |
370
|
|
|
$this->fillParameters('message_id', $parameters); |
371
|
|
|
$this->fillParameters('timestamp', $parameters); |
372
|
|
|
$this->fillParameters('type', $parameters); |
373
|
|
|
$this->fillParameters('user_id', $parameters); |
374
|
|
|
$this->fillParameters('app_id', $parameters); |
375
|
|
|
$this->fillParameters('cluster_id', $parameters); |
376
|
|
|
|
377
|
|
|
$amqpMessage = new AMQPMessage($this->body, $parameters); |
378
|
|
|
return $amqpMessage; |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
private function fillParameters($parameterName, &$parameters) |
382
|
|
|
{ |
383
|
|
|
if ($this->$parameterName !== null) { |
384
|
|
|
$parameters[$parameterName] = $this->$parameterName; |
385
|
|
|
} |
386
|
|
|
} |
387
|
|
|
} |
388
|
|
|
|