line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::RabbitMQ::Client::Method::Publish; |
2
|
5
|
|
|
5
|
|
34
|
use Mojo::Base 'Mojo::RabbitMQ::Client::Method'; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
32
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
sub setup { |
5
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
6
|
|
|
|
|
|
|
|
7
|
0
|
|
|
|
|
|
$self->arguments({@_}); |
8
|
|
|
|
|
|
|
|
9
|
0
|
|
|
|
|
|
return $self; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub deliver { |
13
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
14
|
|
|
|
|
|
|
|
15
|
0
|
0
|
|
|
|
|
return $self if !$self->channel->is_active; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
my %args = %{$self->arguments}; |
|
0
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $header_args |
20
|
0
|
|
0
|
|
|
|
= {header => delete $args{header} || {}, weight => delete $args{weight}}; |
21
|
0
|
|
0
|
|
|
|
my $body = delete $args{body} || ''; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$self->_publish(%args)->_header($header_args, $body)->_body($body, sub { |
24
|
0
|
|
|
0
|
|
|
$self->is_sent(1); |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
$self->emit('success'); |
27
|
0
|
|
|
|
|
|
}); |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
0
|
|
|
|
return $self if !$args{mandatory} && !$args{immediate}; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$self->channel->return_cbs->{($args{exchange} || '') . '_' |
32
|
0
|
|
0
|
|
|
|
. $args{routing_key}} = $self; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _publish { |
38
|
0
|
|
|
0
|
|
|
my $self = shift; |
39
|
0
|
|
|
|
|
|
my %args = @_; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
$self->client->_write_frame( |
42
|
|
|
|
|
|
|
Net::AMQP::Protocol::Basic::Publish->new( |
43
|
|
|
|
|
|
|
exchange => '', |
44
|
|
|
|
|
|
|
mandatory => 0, |
45
|
|
|
|
|
|
|
immediate => 0, |
46
|
|
|
|
|
|
|
%args, # routing_key |
47
|
|
|
|
|
|
|
ticket => 0, |
48
|
|
|
|
|
|
|
), |
49
|
|
|
|
|
|
|
$self->channel->id |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
return $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _header { |
56
|
0
|
|
|
0
|
|
|
my ($self, $args, $body) = @_; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$self->client->_write_frame( |
59
|
|
|
|
|
|
|
Net::AMQP::Frame::Header->new( |
60
|
|
|
|
|
|
|
weight => $args->{weight} || 0, |
61
|
|
|
|
|
|
|
body_size => length($body), |
62
|
|
|
|
|
|
|
header_frame => Net::AMQP::Protocol::Basic::ContentHeader->new( |
63
|
|
|
|
|
|
|
content_type => 'application/octet-stream', |
64
|
|
|
|
|
|
|
content_encoding => undef, |
65
|
|
|
|
|
|
|
headers => {}, |
66
|
|
|
|
|
|
|
delivery_mode => 1, |
67
|
|
|
|
|
|
|
priority => 1, |
68
|
|
|
|
|
|
|
correlation_id => undef, |
69
|
|
|
|
|
|
|
expiration => undef, |
70
|
|
|
|
|
|
|
message_id => undef, |
71
|
|
|
|
|
|
|
timestamp => time, |
72
|
|
|
|
|
|
|
type => undef, |
73
|
|
|
|
|
|
|
user_id => $self->client->user, |
74
|
|
|
|
|
|
|
app_id => undef, |
75
|
|
|
|
|
|
|
cluster_id => undef, |
76
|
0
|
|
0
|
|
|
|
%{ $args->{header} }, |
|
0
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
), |
78
|
|
|
|
|
|
|
), |
79
|
|
|
|
|
|
|
$self->channel->id |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return $self; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _body { |
86
|
0
|
|
|
0
|
|
|
my ($self, $body, $cb) = @_; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$self->client->_write_frame(Net::AMQP::Frame::Body->new(payload => $body), |
89
|
|
|
|
|
|
|
$self->channel->id, $cb); |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
return $self; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=encoding utf8 |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 NAME |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Mojo::RabbitMQ::Client::Method::Publish - single class to do all of AMQP Publish method magic |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SYNOPSIS |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
use Mojo::RabbitMQ::Client::Method::Publish; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $method = Mojo::RabbitMQ::Client::Method::Publish->new( |
107
|
|
|
|
|
|
|
client => $client, |
108
|
|
|
|
|
|
|
channel => $channel |
109
|
|
|
|
|
|
|
)->setup( |
110
|
|
|
|
|
|
|
exchange => 'mojo', |
111
|
|
|
|
|
|
|
routing_key => '', |
112
|
|
|
|
|
|
|
header => {} |
113
|
|
|
|
|
|
|
body => 'mojo', |
114
|
|
|
|
|
|
|
mandatory => 0, |
115
|
|
|
|
|
|
|
immediate => 0, |
116
|
|
|
|
|
|
|
)->deliver(); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 DESCRIPTION |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
L is a special class to implement AMQP message publish workflow. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 EVENTS |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
L inherits all events from L. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
L inherits all attributes from L. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 METHODS |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
L inherits all methods from L with |
133
|
|
|
|
|
|
|
following changes. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 setup |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
$method = $method->setup($arguments); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Only accepts common arguments for message publish chain. Which is: |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=over 2 |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item Frame::Method |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=over 2 |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item Basic::Publish |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=over 2 |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item * exchange |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item * routing_key |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item * mandatory |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item * immediate |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=back |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=back |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item Frame::Header |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=over 2 |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item Basic::ContentHeader |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=over 2 |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item * header |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item * weight |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=back |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=back |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item Frame::Body |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=over 2 |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item * body (as payload) |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=back |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=back |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 SEE ALSO |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
L, L, L |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Copyright (C) 2015-2017, Sebastian Podjasek and others |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Based on L - Copyright (C) 2010 Masahito Ikuta, maintained by C<< bobtfish@bobtfish.net >> |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=cut |