1
|
|
|
<?php |
2
|
|
|
namespace PhpAmqpLib\Message; |
3
|
|
|
|
4
|
|
|
use PhpAmqpLib\Wire\GenericContent; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* A Message for use with the Channnel.basic_* methods. |
8
|
|
|
*/ |
9
|
|
|
class AMQPMessage extends GenericContent |
10
|
|
|
{ |
11
|
|
|
const DELIVERY_MODE_NON_PERSISTENT = 1; |
12
|
|
|
const DELIVERY_MODE_PERSISTENT = 2; |
13
|
|
|
|
14
|
|
|
/** @var string */ |
15
|
|
|
public $body; |
16
|
|
|
|
17
|
|
|
/** @var int */ |
18
|
|
|
public $body_size; |
19
|
|
|
|
20
|
|
|
/** @var bool */ |
21
|
|
|
public $is_truncated = false; |
22
|
|
|
|
23
|
|
|
/** @var string */ |
24
|
|
|
public $content_encoding; |
25
|
|
|
|
26
|
|
|
/** @var array */ |
27
|
|
|
protected static $propertyDefinitions = array( |
28
|
|
|
'content_type' => 'shortstr', |
29
|
|
|
'content_encoding' => 'shortstr', |
30
|
|
|
'application_headers' => 'table_object', |
31
|
|
|
'delivery_mode' => 'octet', |
32
|
|
|
'priority' => 'octet', |
33
|
|
|
'correlation_id' => 'shortstr', |
34
|
|
|
'reply_to' => 'shortstr', |
35
|
|
|
'expiration' => 'shortstr', |
36
|
|
|
'message_id' => 'shortstr', |
37
|
|
|
'timestamp' => 'timestamp', |
38
|
|
|
'type' => 'shortstr', |
39
|
|
|
'user_id' => 'shortstr', |
40
|
|
|
'app_id' => 'shortstr', |
41
|
|
|
'cluster_id' => 'shortstr', |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $body |
46
|
|
|
* @param array $properties |
47
|
|
|
*/ |
48
|
168 |
|
public function __construct($body = '', $properties = array()) |
49
|
|
|
{ |
50
|
168 |
|
$this->setBody($body); |
51
|
168 |
|
parent::__construct($properties, static::$propertyDefinitions); |
52
|
168 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
12 |
|
public function getBody() |
58
|
|
|
{ |
59
|
12 |
|
return $this->body; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Sets the message payload |
64
|
|
|
* |
65
|
|
|
* @param string $body |
66
|
|
|
* @return $this |
67
|
|
|
*/ |
68
|
168 |
|
public function setBody($body) |
69
|
|
|
{ |
70
|
168 |
|
$this->body = $body; |
71
|
|
|
|
72
|
168 |
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
6 |
|
public function getContentEncoding() |
79
|
|
|
{ |
80
|
6 |
|
return $this->content_encoding; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return int |
85
|
|
|
*/ |
86
|
66 |
|
public function getBodySize() |
87
|
|
|
{ |
88
|
66 |
|
return $this->body_size; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param int $body_size Message body size in byte(s) |
93
|
|
|
* @return AMQPMessage |
94
|
|
|
*/ |
95
|
66 |
|
public function setBodySize($body_size) |
96
|
|
|
{ |
97
|
66 |
|
$this->body_size = (int) $body_size; |
98
|
|
|
|
99
|
66 |
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return boolean |
104
|
|
|
*/ |
105
|
6 |
|
public function isTruncated() |
106
|
|
|
{ |
107
|
6 |
|
return $this->is_truncated; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param bool $is_truncated |
112
|
|
|
* @return AMQPMessage |
113
|
|
|
*/ |
114
|
6 |
|
public function setIsTruncated($is_truncated) |
115
|
|
|
{ |
116
|
6 |
|
$this->is_truncated = (bool) $is_truncated; |
117
|
|
|
|
118
|
6 |
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return int |
123
|
|
|
* |
124
|
|
|
* @throws \PhpAmqpLib\Exception\AMQPEmptyDeliveryTagException |
125
|
|
|
*/ |
126
|
6 |
|
public function getDeliveryTag() |
127
|
|
|
{ |
128
|
6 |
|
if (!isset($this->delivery_info['delivery_tag'])) { |
129
|
6 |
|
throw new \PhpAmqpLib\Exception\AMQPEmptyDeliveryTagException(); |
130
|
|
|
} |
131
|
|
|
|
132
|
6 |
|
return (int) $this->delivery_info['delivery_tag']; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|