Amazon-SQS-Client

 view release on metacpan or  search on metacpan

ChangeLog  view on Meta::CPAN

	* NEWS: update for new version
	* resources/*: removed
	* configure.ac: remove above
	* Makefile.am
	- change install dir to $datadir/amazon-sqs
	- remove required-modules
	- remove resources
	* src/main/bash/bin/aws-sqsd.in: check for .ini file
	* src/main/perl/bin/create-queue.pl.in: pod tweaks & fixes
	* src/main/lib/Amazon/SQS/QueueHandler.pm.in
	(decode_message): save decoded message
	* src/main/perl/lib/Amazon/SQS/Client.pm.in: perlcritic cleanup
	* src/main/perl/lib/Amazon/SQS/Exception.pm.in: likewise
	* src/main/perl/lib/Amazon/SQS/Model.pm.in: likewise
	* src/main/perl/lib/Amazon/SQS/Model/Message.pm.in: likewise
	* src/main/perl/lib/Amazon/SQS/Model/ReceiveMessageRequest.pm.in: likewise
	* src/main/perl/lib/Amazon/SQS/Model/ReceiveMessageResponse.pm.in: likewise
	* src/main/perl/lib/Amazon/SQS/Model/SendMessageRequest.pm.in: likewise
	* src/main/perl/lib/Amazon/SQS/Model/SendMessageResponse.pm.in: likewise
	* src/main/perl/lib/Amazon/SQS/Constants.pm.in: new
	* src/main/perl/lib/Makefile.am: add above to build

bin/QueueDaemon.pl  view on Meta::CPAN

=item 3. See L<Amazon::SQS::Config> regarding the available options in a config file.

=item 4. The default is to daemonize the script. Use --no-daemonize to run in a terminal.

=item 5. If you do not provide a handler on the command line or in
your .ini file the default handler will be used. The default hanlder will dump the
message to the log and delete the message.

=item 6. By default messages will only be deleted from the queue if your
handler returns a true value. If you want to delete messages which cannot be
decoded or when you handler returns a non-true value, set the
--delete-when or set 'delete' option in the [error] section of your .ini file.

=item 7. To exit the daemon when your handler returns a non-true value
set the --exit-when option to 'false' or in the [error] section of your .ini
file, set 'exit = false'.

=item 8. To exit the daemon if your handler throws an exception, 
set the --exit-when option to 'error' or in the [error] section of your .ini
file, set 'exit = error'.

lib/Amazon/SQS/Config.pm  view on Meta::CPAN


Name of the class that implements your handler.  If you do not provide
a class the default class L<Amazon::SQS::QueueHandler> is used.  That
class will dump and delete each message it reads.

=item message_type

The message mime type. Can be one of 'text/plain', 'application/json',
or 'application/x-www-form-urlencoded'.

If the message type is 'application/json' it will be decoded using the
L<JSON> class. If the message type is
'application/x-www-form-urlencoded' the message will be decode using
L<CGI::Simple> and returned as a hash reference.

default: text/plain

I<NOTE: The message sent to your handler is the decoded message. The
raw message is available using the C<get_raw_message> method. The
decoded messsage is also available using the getter C<get_message>.>

=item max_children

The maximum number of children that can be instantiated by the
F<QueuDaemon.pl> script.  Currently the maximum is 1.  Future versions
may support forking.

=item pidfile

Path of the pid file.

lib/Amazon/SQS/QueueHandler.pm  view on Meta::CPAN

  $message_body //= $self->get_message_body;

  $self->get_logger->trace(
    Dumper(
      [ type => $message_type,
        body => $message_body,
      ]
    )
  );

  my $decoded_message = eval {
    return $message_body
      if $message_type eq 'text/plain';

    return JSON->new->decode($message_body)
      if $message_type eq 'application/json';

    if ( $message_type eq 'application/x-www-form-encoded' ) {
      my %vars = CGI::Simple->new($message_body)->Vars();

      # create array refs from multi-value params
      foreach ( keys %vars ) {
        next if $vars{$_} !~ /\0/;
        $vars{$_} = [ split /\0/xsm, $vars{$_} ];
      }

      return \%vars;
    }
  };

  die "unable to decode message\n$EVAL_ERROR"
    if !defined $decoded_message || $EVAL_ERROR;

  $self->set_message($decoded_message);

  return $decoded_message;
}

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

  $self->get_logger->info( Dumper( [ message => $message ] ) );

  return $TRUE;

lib/Amazon/SQS/QueueHandler.pm  view on Meta::CPAN

    if !ref $message || !$message->isSetMessageId();

  $self->set_raw_message($message);

  $self->set_receipt_handle( $message->getReceiptHandle );

  $self->set_message_body( $message->getBody() );

  $self->set_message_id( $message->getMessageId() );

  my $decoded_message = $self->decode_message();

  $self->set_message($decoded_message);

  return $decoded_message;
}

########################################################################
sub create_request {
########################################################################
  my ($self) = @_;

  return $self->get_request
    if $self->get_request;

lib/Amazon/SQS/QueueHandler.pm  view on Meta::CPAN

F<QueueDaemon.pl> script.  You provide a handler class that processes
SQS messages. The F<QueueDaemon.pl> script handles the plumbing.

=head1 METHODS AND SUBROUTINES

=head2 handler

 handler(message)

You provide your own handler message that receives a message to
process. The message is the decoded body of the message placed on the
SQS queue by some other process. Messages can be sent as plain text,
JSON strings or x-www-form-encoded strings.

Generally speaking, by default your handler should return a true value
if you want the message deleted and a non-zero value if you want the
message to be returned to the queue. There are various options
available with the F<QueueDaemon.pl> script that control this behavior
however.

=head2 change_message_visibility



( run in 0.528 second using v1.01-cache-2.11-cpan-49f99fa48dc )