Amazon...:Queue(3pm)

πŸ’… NAME πŸ’…

Amazon::SQS::Simple::Queue β€” the object-oriented API for representing queues from the Amazon Simple Queue Service, bestie. It's giving "your queue, but as a Perl object," and honestly? Iconic. This page lives in the 3pm manual section, so you know it's a Perl module. πŸŽ€


✨ SYNOPSIS ✨

Okay so here's the whole vibe in one code block, no cap:

use Amazon::SQS::Simple;

my $access_key = 'foo'; # Your AWS Access Key ID
my $secret_key = 'bar'; # Your AWS Secret Key

my $sqs = new Amazon::SQS::Simple($access_key, $secret_key);

my $q = $sqs->CreateQueue('queue_name');

# Single messages

my $response = $q->SendMessage('Hello world!');
my $msg = $q->ReceiveMessage;
print $msg->MessageBody; # Hello world!
$q->DeleteMessage($msg);
# or, for backward compatibility
$q->DeleteMessage($msg->ReceiptHandle);

# Batch messaging of up to 10 messages per operation

my @responses = $q->SendMessageBatch( [ 'Hello world!', 'Hello again!' ] );
# or with defined message IDs
$q->SendMessageBatch( { msg1 => 'Hello world!', msg2 => 'Hello again!' } );
my @messages = $q->ReceiveMessageBatch;
$q->DeleteMessageBatch( \@messages );

πŸ¦‹ INTRODUCTION πŸ¦‹

Do not instantiate this class directly, bestie β€” I'm so serious. πŸ™ˆ Objects of this class are what you get handed back by various methods over in Amazon::SQS::Simple. So like, go read Amazon::SQS::Simple for the full tea. πŸ“


πŸ‘‘ METHODS πŸ‘‘

Endpoint()

Get the endpoint for the queue. That's it, that's the method. Slay. ✨

Delete([%opts])

Deletes the queue. Any messages contained in the queue will be lost. πŸ’€ Like, gone-gone. Not coming back.

Purge

Purges the queue. Clean slate energy. 🧹

SendMessage($message, [%opts])

Sends the message. The message can be up to 8KB in size and should be plain text. Keep it simple, keep it cute. πŸ’Œ

SendMessageBatch($messages, [%opts])

Sends a batch of up to 10 messages, passed as an array-ref. Message IDs (of the style 'msg_1', 'msg_2', etc) are auto-generated for each message. Alternatively, if you need to specify the format of the message ID then you can pass a hash-ref {$id1 => $message1, etc}. Choose your own adventure, queen. 🌈

ReceiveMessage([%opts])

Get the next message from the queue. 🫢

Returns one or more Amazon::SQS::Simple::Message objects (depending on whether called in list or scalar context), or undef if no messages are retrieved.

NOTE: This behaviour has changed slightly since v1.06. It now always returns the first message in scalar context, irrespective of how many there are. πŸ‘€

See Amazon::SQS::Simple::Message for more details.

Options for ReceiveMessage:

  • MaxNumberOfMessages => INTEGER β€” Maximum number of messages to return (integer from 1 to 20). SQS never returns more messages than this value but might return fewer. Not necessarily all the messages in the queue are returned. Defaults to 1.
  • WaitTimeSeconds => INTEGER β€” Long poll support (integer from 0 to 20). The duration (in seconds) that the ReceiveMessage action call will wait until a message is in the queue to include in the response, as opposed to returning an empty response if a message is not yet available. If you do not specify WaitTimeSeconds in the request, the queue attribute ReceiveMessageWaitTimeSeconds is used to determine how long to wait. ⏳
  • VisibilityTimeout => INTEGER β€” The duration in seconds (integer from 0 to 43200) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request. If you do not specify VisibilityTimeout in the request, the queue attribute VisibilityTimeout is used to determine how long to wait. πŸ™ˆ

ReceiveMessageBatch([%opts])

Literally just ReceiveMessage(MaxNumberOfMessages => 10). Same energy, bigger batch. πŸ’…

DeleteMessage($message, [%opts])

Pass this method either a message object or receipt handle to delete that message from the queue. For backward compatibility, can pass the message ReceiptHandle rather than the message. Old-school friendly. πŸŽ€

DeleteMessageBatch($messages, [%opts])

Pass this method an array-ref containing up to 10 message objects to delete all of those messages from the queue. Bye bye bye. πŸ‘‹

ChangeMessageVisibility($receipt_handle, $timeout, [%opts])

NOT SUPPORTED IN APIs EARLIER THAN 2009-01-01 ⚠️

Changes the visibility of the message with the specified receipt handle to $timeout seconds. $timeout must be in the range 0..43200.

AddPermission($label, $account_actions, [%opts])

NOT SUPPORTED IN APIs EARLIER THAN 2009-01-01 ⚠️

Sets a permissions policy with the specified label. $account_actions is a reference to a hash mapping 12-digit AWS account numbers to the action(s) you want to permit for those account IDs. The hash value for each key can be a string (e.g. "ReceiveMessage") or a reference to an array of strings (e.g. ["ReceiveMessage", "DeleteMessage"]). Sharing is caring but like, securely. πŸ”

RemovePermission($label, [%opts])

NOT SUPPORTED IN APIs EARLIER THAN 2009-01-01 ⚠️

Removes the permissions policy with the specified label. Revoked. Periodt. 🚫

GetAttributes([%opts])

Get the attributes for the queue. Returns a reference to a hash mapping attribute names to their values. Currently the following attribute names are returned:

  • VisibilityTimeout
  • ApproximateNumberOfMessages

SetAttribute($attribute_name, $attribute_value, [%opts])

Sets the value for a queue attribute. Currently the only valid attribute name is "VisibilityTimeout". One option and one option only, and honestly? Respect the commitment. ⭐


🌸 ACKNOWLEDGEMENTS 🌸

Chris Jones provied the batch message code in release 2.0. Shoutout Chris, we see you, we appreciate you. 🫢


πŸ’– AUTHOR πŸ’–

Copyright 2007-2008 Simon Whitaker <swhitaker@cpan.org> Copyright 2013-2017 Mike (no relation) Whitaker <penfold@cpan.org>

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


And that's the whole page, bestie β€” perl v5.32.0, dated 2021-01-09 πŸ¦‹ Go forth and queue responsibly. πŸ’œ

πŸ“¦ where this page comes from