1
package Amazon::SQS::Simple::Queue;
5
use Amazon::SQS::Simple::Message;
6
use Amazon::SQS::Simple::SendResponse;
8
use base 'Amazon::SQS::Simple::Base';
9
use Amazon::SQS::Simple::Base; # for constants
11
use overload '""' => \&_to_string;
15
return $self->{Endpoint};
20
my $force = shift; # from API 2007-05-01
21
my $params = { Action => 'DeleteQueue' };
22
$params->{ForceDeletion} = 'true' if $force && $self->_api_version() eq +SQS_VERSION_2007_05_01;
24
my $href = $self->_dispatch($params);
28
my ($self, $message, %params) = @_;
30
$params{Action} = 'SendMessage';
31
$params{MessageBody} = $message;
33
my $href = $self->_dispatch(\%params);
35
if ($self->_api_version() eq +SQS_VERSION_2007_05_01) {
36
return new Amazon::SQS::Simple::SendResponse(
41
# default to most recent version
42
return new Amazon::SQS::Simple::SendResponse(
43
$href->{SendMessageResult}
49
my ($self, %params) = @_;
51
$params{Action} = 'ReceiveMessage';
53
my $href = $self->_dispatch(\%params, [qw(Message)]);
57
if ($self->_api_version() eq +SQS_VERSION_2007_05_01) {
58
if (defined $href->{Message}) {
59
foreach (@{$href->{Message}}) {
60
push @messages, new Amazon::SQS::Simple::Message(
68
# default to most recent version
69
if (defined $href->{ReceiveMessageResult}{Message}) {
70
foreach (@{$href->{ReceiveMessageResult}{Message}}) {
71
push @messages, new Amazon::SQS::Simple::Message(
79
if (@messages > 1 || wantarray) {
89
my ($self, $receipt_handle, %params) = @_;
91
$params{Action} = 'DeleteMessage';
92
if ($self->_api_version() eq +SQS_VERSION_2007_05_01) {
93
$params{MessageId} = $receipt_handle;
96
# default to the current version
97
$params{ReceiptHandle} = $receipt_handle;
100
my $href = $self->_dispatch(\%params);
104
my ($self, %params) = @_;
106
$params{Action} = 'GetQueueAttributes';
109
if ($self->_api_version() eq +SQS_VERSION_2007_05_01) {
110
$params{Attribute} ||= 'All';
112
my $href = $self->_dispatch(\%params, [ 'AttributedValue' ]);
114
if ($href->{'AttributedValue'}) {
115
foreach my $attr (@{$href->{'AttributedValue'}}) {
116
$result{$attr->{Attribute}} = $attr->{Value};
121
# default to the current version
122
$params{AttributeName} ||= 'All';
124
my $href = $self->_dispatch(\%params, [ 'Attribute' ]);
126
if ($href->{GetQueueAttributesResult}) {
127
foreach my $attr (@{$href->{GetQueueAttributesResult}{Attribute}}) {
128
$result{$attr->{Name}} = $attr->{Value};
137
my ($self, $key, $value, %params) = @_;
139
$params{Action} = 'SetQueueAttributes';
140
if ($self->_api_version() eq +SQS_VERSION_2007_05_01) {
141
$params{Attribute} = $key;
142
$params{Value} = $value;
145
# default to the current version
146
$params{'Attribute.Name'} = $key;
147
$params{'Attribute.Value'} = $value;
150
my $href = $self->_dispatch(\%params);
155
return $self->Endpoint();
164
Amazon::SQS::Simple::Queue - OO API for representing queues from
165
the Amazon Simple Queue Service.
169
use Amazon::SQS::Simple;
171
my $access_key = 'foo'; # Your AWS Access Key ID
172
my $secret_key = 'bar'; # Your AWS Secret Key
174
my $sqs = new Amazon::SQS::Simple($access_key, $secret_key);
176
my $q = $sqs->CreateQueue('queue_name');
178
$q->SendMessage('Hello world!');
180
my $msg = $q->ReceiveMessage();
182
print $msg->MessageBody() # Hello world!
184
$q->DeleteMessage($msg->MessageId());
188
Don't instantiate this class directly. Objects of this class are returned
189
by various methods in C<Amazon::SQS::Simple>. See L<Amazon::SQS::Simple> for
198
Get the endpoint for the queue.
200
=item B<Delete([%opts])>
202
Deletes the queue. Any messages contained in the queue will be lost.
204
=item B<SendMessage($message, [%opts])>
206
Sends the message. The message can be up to 8KB in size and should be
209
=item B<ReceiveMessage([%opts])>
211
Get the next message from the queue.
213
Returns an C<Amazon::SQS::Simple::Message> object. See
214
L<Amazon::SQS::Simple::Message> for more details.
216
If MaxNumberOfMessages is greater than 1, the method returns
217
an array of C<Amazon::SQS::Simple::Message> objects.
219
Options for ReceiveMessage:
223
=item * MaxNumberOfMessages => NUMBER
225
Maximum number of messages to return. Value should be an integer between 1
226
and 10 inclusive. Default is 1.
230
=item B<DeleteMessage($receipt_handle, [%opts])>
232
Delete the message with the specified receipt handle from the queue
234
=item B<GetAttributes([%opts])>
236
Get the attributes for the queue. Returns a reference to a hash
237
mapping attribute names to their values. Currently the following
238
attribute names are returned:
242
=item * VisibilityTimeout
244
=item * ApproximateNumberOfMessages
248
=item B<SetAttribute($attribute_name, $attribute_value, [%opts])>
250
Sets the value for a queue attribute. Currently the only valid
251
attribute name is C<VisibilityTimeout>.
257
Copyright 2007-2008 Simon Whitaker E<lt>swhitaker@cpan.orgE<gt>
259
This program is free software; you can redistribute it and/or modify it
260
under the same terms as Perl itself.