NAME

SQS::Queue::Worker - parent class for queue processing handlers.

SYNOPSIS

package SQS::Queue::Worker::FumanQueue

use parent qw(SQS::Queue::Worker);

sub handler {
  my ($self) = @_;

  my $message = $self->get_last_message();
  my $body = $self->get_body;

  # or
  $self->parse_message();
  my $params = $self->get_message_params();

  return 1;
}

1;

DESCRIPTION

SQS::Queue::Worker is a base class for writing Amazon Simple Queue Service (SQS) message handlers.

VERSION

This documentation refers to version 1.0.3.

NOTES

This base class is one element in a simple architecture to handle messages from the SQS queue. Follow the cookbook below to implement handlers for your workflow.

LONG POLLING

By default, the script will read messages from the SQS queue using long polling. You can configure the wait time by setting the wait_time_seconds parameter in the configuration file. If you want to disable long polling, set the wait_time_seconds to 0.

default: 20s

METHODS AND SUBROUTINES

new

new()

LOGGING METHODS

init_logger

Initializes a Log::Log4perl log file.

get_logger

Returns the current logging object.

QUEUE METHODS

get_queue_url, set_queue_url

Returns the current queue URL.

get_poll_interval, set_poll_interval

get_poll_interval()

get_max_sleep_period, set_max_sleep_period

Returns the max sleep period. The system will increment the sleep period until this value.

get_visibility_timeout, set_visibility_timeout

create_sqs_message

create_sqs_message( options )

Creates a formatted message that can be sent to an SQS queue.

options is a hash of key/value pairs specific to the message. You should at least have an event key defined.

Example:

my $payload = create_sqs_message( event => 'process', key => 'spool/52/foo.jpg', account => 52);

This method can also be called as a class method.

use SQS::Queue::Worker qw(crate_sqs_message);

create_sqs_message(message-body)

If you pass a reference it will be formatted as a JSON string.

delete_message

delete_message( message )

Deletes an SQS message from the queue.

parse_message

parse_message()

Returns a hash reference containing the parameters passed in the message. Message parameters are passed as CGI query strings or a JSON object.

This method can also be called as a class method.

use SQS::Queue::Worker qw(parse_message);

parse_message(message-body)

read_message

read_message()

Returns an SQS message body or undef.

get_last_message

get_last_message()

Returns the last message read.

send_message

send_message( message );

Sends a message on the current current queue.

change_message_visibility

change_message_visibility( message, timeout );

Changes the message visibility so that the message will not be available for a given number of seconds. We typically use this when we have reached the maxium number of messages we want to process at one time for a queue and want to delay the availabity of this message for some time.

handler

handler

You should implement a handler.

SEE ALSO

Amazon::API::SQS, Proc::Daemon

AUTHOR

Rob Lauer - rclauer@gmail.com

LICENSE

Copyright (c) 2025 TBC Development Group, LLC. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.