-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathREADME
207 lines (158 loc) · 6.61 KB
/
README
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
NAME
POE::Component::Client::AMQP - Asynchronous AMQP client implementation
in POE
SYNOPSIS
use POE::Component::Client::AMQP;
Net::AMQP::Protocol->load_xml_spec('amqp0-8.xml');
my $amq = POE::Component::Client::AMQP->create(
RemoteAddress => 'mq.domain.tld',
);
$amq->channel(1)->queue('frank')->subscribe(sub {
my ($payload, $meta) = @_;
my $reply_to = $meta->{header_frame}->reply_to;
$amq->channel(1)->queue($reply_to)->publish("Message received");
});
$amq->run();
DESCRIPTION
This module implements the Advanced Message Queue Protocol (AMQP) TCP/IP
client. It's goal is to provide users with a quick and easy way of using
AMQP while at the same time exposing the advanced functionality of the
protocol if needed.
The (de)serialization and representation logic is handled by Net::AMQP,
which needs to be setup (via load_xml_spec()) prior to this client
software running. Please see the docs there for further information on
this.
USAGE
create
my $amq = POE::Component::Client::AMQP->create(
RemoteAddress => 'mq.domain.tld',
);
Create a new AMQP client. Arguments to this method:
*RemoteAddress* (default: 127.0.0.1)
Connect to this host
*RemotePort* (default: 5672)
*Username* (default: guest)
*Password* (default: guest)
*VirtualHost* (default: /)
*Logger* (default: simple screen logger)
Provide an object which implements 'debug', 'info' and 'error'
logging methods (such as Log::Log4perl).
*Debug*
This module provides extensive debugging options. These are
specified as a hash as follows:
*logic* (boolean)
Display decisions the code is making
*frame_input* (boolean)
*frame_output* (boolean)
Use the *frame_dumper* code to display frames that come in from
or out to the server.
*frame_dumper* (coderef)
A coderef which, given a Net::AMQP::Frame object, will return a
string representation of it, prefixed with "\n".
*raw_input* (boolean)
*raw_output* (boolean)
Use the *raw_dumper* code to display raw data that comes in from
or out to the server.
*raw_dumper* (coderef)
A coderef which, given a raw string, will return a byte
representation of it, prefixed with "\n".
*Keepalive* (default: 0)
If set, will send a Net::AMQP::Frame::Heartbeat frame every
Keepalive seconds after the last activity on the connection. This is
a mechanism to keep a long-open TCP session alive.
*Alias* (default: amqp_client)
The POE session alias of the main client session
*AliasTCP* (default: tcp_client)
The POE session alias of the TCP client
*Callbacks* (default: {})
Provide callbacks. At the moment, 'Startup' and 'FrameSent' are the
only recognized callback.
FrameSent will be called with $self and the Net::AMQP::Frame being
sent.
*is_testing*
Set to '1' to avoid creating POE::Sessions (mainly useful in t/
scripts)
Returns a class object.
CLASS METHODS
do_when_startup (...)
Pass a subref that should be executed after the client has connected
and authenticated with the remote AMQP server. If the client is
already connected and authenticated, the subref will be called
immediately. Think: deferred.
channel ($id)
Call with an optional argument $id (1 - 65536). Returns a
POE::Component::Client::AMQP::Channel object which can be used
immediately.
run ()
Shortcut to calling $poe_kernel->run
stop ()
Shortcut to calling the POE state 'disconnect'
compose_basic_publish ($payload, %options)
A helper method to generate the frames necessary for a basic
publish. Returns a Net::AMQP::Protocol::Basic::Publish,
Net::AMQP::Frame::Header (wrapping a
Net::AMQP::Protocol::Basic::ContentHeader frame) followed by zero or
more Net::AMQP::Frame::Body frames. Since the arguments for each one
of these frames are unique, the %options hash provides options for
all of the frames.
The following options are supported, all of which are optional, some
having sane defaults:
*Header options*
*weight* (default: 0)
*Method options*
*ticket* (default: 0)
*exchange*
*routing_key*
*mandatory* (default: 1)
*immediate*
*Content options*
*content_type*
*content_encoding*
*headers* (default: {})
*delivery_mode* (default: 1)
*priority* (default: 1)
*correlation_id*
*reply_to*
*expiration*
*message_id*
*timestamp*
*type*
*user_id*
*app_id*
*cluster_id*
POE STATES
The following are states you can post to to interact with the client.
Use the alias defined in the "create()" call above.
server_disconnect
Send a Connection.Close request
server_send (@output)
Pass one or more Net::AMQP::Frame objects. For short hand, you may
pass Net::AMQP::Protocol::Base objects, which will be automatically
wrapped in the appropriate frame type, with channel 0. These frames
will be written to the server. In the case of
Net::AMQP::Frame::Method objects which are calling a synchronous
method, the client will handle them one at a time, waiting until a
synchronous method returns properly before sending further
synchronous frames. This happens automatically.
shutdown ()
If you need to stop things immediately, call shutdown(). This is not
graceful.
keepalive
Sends a Heartbeat frame at a regular interval to keep the TCP session
from timing out.
SEE ALSO
POE, Net::AMQP
DEVELOPMENT
This module is being developed via a git repository publicly avaiable at
http://github.com/ewaters/poe-component-client-amqp. I encourage anyone
who is interested to fork my code and contribute bug fixes or new
features, or just have fun and be creative.
COPYRIGHT
Copyright (c) 2009 Eric Waters and XMission LLC
(http://www.xmission.com/). All rights reserved. This program is free
software; you can redistribute it and/or modify it under the same terms
as Perl itself.
The full text of the license can be found in the LICENSE file included
with this module.
AUTHOR
Eric Waters <[email protected]>