line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crixa::Message; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
5
|
1
|
|
|
1
|
|
4
|
use namespace::autoclean; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
67
|
use Moose; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
4756
|
use Math::Int64 0.34; |
|
1
|
|
|
|
|
1610
|
|
|
1
|
|
|
|
|
5
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has channel => ( |
14
|
|
|
|
|
|
|
isa => 'Crixa::Channel', |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
required => 1, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has body => ( |
20
|
|
|
|
|
|
|
is => 'ro', |
21
|
|
|
|
|
|
|
isa => 'Str', |
22
|
|
|
|
|
|
|
required => 1, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
{ |
26
|
|
|
|
|
|
|
my @properties = qw( |
27
|
|
|
|
|
|
|
content_type |
28
|
|
|
|
|
|
|
content_encoding |
29
|
|
|
|
|
|
|
correlation_id |
30
|
|
|
|
|
|
|
reply_to |
31
|
|
|
|
|
|
|
expiration |
32
|
|
|
|
|
|
|
message_id |
33
|
|
|
|
|
|
|
type |
34
|
|
|
|
|
|
|
user_id |
35
|
|
|
|
|
|
|
app_id |
36
|
|
|
|
|
|
|
priority |
37
|
|
|
|
|
|
|
delivery_mode |
38
|
|
|
|
|
|
|
timestamp |
39
|
|
|
|
|
|
|
headers |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has _properties => ( |
43
|
|
|
|
|
|
|
traits => ['Hash'], |
44
|
|
|
|
|
|
|
is => 'bare', |
45
|
|
|
|
|
|
|
isa => 'HashRef', |
46
|
|
|
|
|
|
|
init_arg => 'props', |
47
|
|
|
|
|
|
|
required => 1, |
48
|
|
|
|
|
|
|
handles => { |
49
|
|
|
|
|
|
|
map { ( $_ => [ 'get', $_ ], 'has_' . $_ => [ 'exists', $_ ], ) } |
50
|
|
|
|
|
|
|
@properties |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
has redelivered => ( |
56
|
|
|
|
|
|
|
is => 'ro', |
57
|
|
|
|
|
|
|
isa => 'Bool', |
58
|
|
|
|
|
|
|
required => 1, |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has routing_key => ( |
62
|
|
|
|
|
|
|
is => 'ro', |
63
|
|
|
|
|
|
|
isa => 'Str', |
64
|
|
|
|
|
|
|
required => 1, |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
has exchange => ( |
68
|
|
|
|
|
|
|
is => 'ro', |
69
|
|
|
|
|
|
|
isa => 'Str', |
70
|
|
|
|
|
|
|
required => 1, |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
has delivery_tag => ( |
74
|
|
|
|
|
|
|
is => 'ro', |
75
|
|
|
|
|
|
|
isa => 'Math::UInt64', |
76
|
|
|
|
|
|
|
required => 1, |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
has message_count => ( |
80
|
|
|
|
|
|
|
is => 'ro', |
81
|
|
|
|
|
|
|
isa => 'Int', |
82
|
|
|
|
|
|
|
predicate => '_has_message_count', |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
has consumer_tag => ( |
86
|
|
|
|
|
|
|
is => 'ro', |
87
|
|
|
|
|
|
|
isa => 'Str', |
88
|
|
|
|
|
|
|
predicate => '_has_consumer_tag', |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub BUILD { |
92
|
18
|
|
|
18
|
0
|
14
|
my $self = shift; |
93
|
|
|
|
|
|
|
|
94
|
18
|
50
|
66
|
|
|
519
|
die 'A Crixa::Message must have a message_count or consumer_tag' |
95
|
|
|
|
|
|
|
unless $self->_has_message_count() || $self->_has_consumer_tag(); |
96
|
|
|
|
|
|
|
|
97
|
18
|
|
|
|
|
322
|
return; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub ack { |
101
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
102
|
0
|
|
|
|
|
|
$self->channel->ack( $self->delivery_tag ); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# ABSTRACT: A Crixa Message |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=pod |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 NAME |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Crixa::Message - A Crixa Message |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 VERSION |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
version 0.12 |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 DESCRIPTION |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This class represents a single queue. With RabbitMQ, messages are published to |
126
|
|
|
|
|
|
|
exchanges, which then routes the message to one or more queues. You then |
127
|
|
|
|
|
|
|
consume those messages from the queue. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=encoding UTF-8 |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 METHODS |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This class provides the following methods: |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 $message->ack |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This send an acknowledgement for the message on the channel that was used to |
138
|
|
|
|
|
|
|
receive the message. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 $message->body |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This returns the message's body. If the message does not have any |
143
|
|
|
|
|
|
|
content-encoding set _or_ the message contains an encoding with the string |
144
|
|
|
|
|
|
|
"utf-8" (case insensitive), then the message is returned as character |
145
|
|
|
|
|
|
|
data. Otherwise it is returned as binary data. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 Property methods |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
There are a number of properties that can be associated with a message. This |
150
|
|
|
|
|
|
|
class provides reader and predicate methods for all properties of the form C<< |
151
|
|
|
|
|
|
|
$message->foo >> and C<< $message->has_foo >>. None of the properties are |
152
|
|
|
|
|
|
|
required. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
The properties supported are: |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=over 4 |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item * content_type |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item * content_encoding |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item * correlation_id |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item * reply_to |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item * expiration |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item * message_id |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item * type |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item * user_id |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item * app_id |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item * priority |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item * delivery_mode |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * timestamp |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item * headers |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=back |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
See the C<publish> method in the L<Crixa::Exchange> docs for more details. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head2 $message->redelivered |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
A boolean indicating whether or not the message has already been delivered at |
191
|
|
|
|
|
|
|
least once. RabbitMQ guarantees that each message will be delivered I<at least |
192
|
|
|
|
|
|
|
once>, and it is not uncommon for a message to be redelivered before the first |
193
|
|
|
|
|
|
|
consumer to receive it has had a chance to acknowledge it. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head2 $message->message_count |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
The number of messages left in the queue at the time this message was |
198
|
|
|
|
|
|
|
delivered. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Note that this is only set for messages which are not received via the C<< |
201
|
|
|
|
|
|
|
Crixa::Queue->consume() >> method. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head2 $message->routing_key |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
The routing path on which the message was received. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head2 $message->exchange |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
The exchange to which this message was published |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head2 $message->delivery_tag |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
The delivery tag for a given message. This is used when the C<< |
214
|
|
|
|
|
|
|
$message->ack() >> method is called. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head2 $message->consumer_tag |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
The tag for the consumer associated with the message, if one exists. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Note that this is only set for messages which are received via the C<< |
221
|
|
|
|
|
|
|
Crixa::Queue->consume() >> method. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head2 Crixa::Message->new(...) |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
There is no reason to call this method directly. It will be called by a |
226
|
|
|
|
|
|
|
L<Crixa::Queue> object to inflate messages into objects. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 AUTHORS |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=over 4 |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item * |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Chris Prather <chris@prather.org> |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=item * |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=back |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
This software is copyright (c) 2012 - 2015 by Chris Prather. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
247
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=cut |