view release on metacpan or search on metacpan
bin/QueueDaemon.pl view on Meta::CPAN
$SIG{HUP} = sub {
print {*STDERR} "Caught SIGHUP: re-reading config file.\n";
$KEEP_GOING = $TRUE;
my $config = load_config($options);
${$handler} = load_handler(
options => $options,
logger => ${$handler}->get_logger,
credentials => ${$handler}->get_credentials,
config => $config,
);
init_logger($options); # just reset loglevel (potentially)
$RELOAD = $TRUE;
};
$SIG{INT} = sub {
print {*STDERR} ("Caught SIGINT: exiting gracefully\n");
bin/QueueDaemon.pl view on Meta::CPAN
$options->{'wait-time'} //= $config->get_queue_wait_time;
return $config;
}
########################################################################
sub load_handler {
########################################################################
my %args = @_;
my ( $config, $options, $logger, $credentials ) = @args{qw(config options logger credentials)};
if ( Class::Inspector->loaded( $options->{handler} ) ) {
Class::Unload->unload( $options->{handler} );
}
autoload $options->{handler};
my $handler = $options->{handler}->new(
config => $config,
logger => $logger,
endpoint_url => $options->{endpoint_url},
name => $options->{queue},
url => $options->{'queue-url'},
message_type => $options->{'message-type'},
create_queue => $options->{'create-queue'},
wait_time => $options->{'wait-time'},
visibility_timeout => $options->{'visibility-timeout'},
credentials => $credentials,
);
die "not an Amazon::SQS::QueueHandler\n"
if !$handler->isa('Amazon::SQS::QueueHandler');
return $handler;
}
########################################################################
sub sleep_time {
bin/create-queue.pl view on Meta::CPAN
########################################################################
sub init_client {
########################################################################
my ($options) = @_;
my $client_options = {
ServiceURL => $options->{'endpoint-url'},
$options->{debug} ? ( loglevel => 'debug' ) : ( loglevel => 'info' ),
};
my @credentials = ( $ENV{AWS_ACCESS_KEY_ID}, $ENV{AWS_SECRET_ACCESS_KEY} );
return Amazon::SQS::Client->new( @credentials, $client_options );
}
########################################################################
sub main {
########################################################################
my @option_specs = qw(
debug|d
dlq!
delay-seconds|D=i
endpoint-url|e=s
lib/Amazon/SQS/Client.pm view on Meta::CPAN
qw(
ServiceURL
UserAgent
SignatureVersion
SignatureMethod
MaxErrorRetry
ServiceVersion
SecurityToken
Region
v4_signer
credentials
last_request
last_response
)
);
use parent qw(Class::Accessor::Fast);
our $VERSION = '@PACKAGE_VERSION';
########################################################################
sub new {
########################################################################
my ( $class, @args ) = @_;
my $options;
if ( ref $args[0] ) {
$options = $args[0];
}
elsif ( $args[0] && $args[1] ) {
my $credentials = Amazon::SQS::Credentials->new(@args);
$options = { credentials => $credentials };
if ( ref $args[2] ) {
$options = { %{$options}, %{ $args[2] } };
}
}
else {
$options = ref $args[2] ? $args[2] : {};
$options->{credentials} //= Amazon::Credentials->new();
}
set_defaults($options);
my $self = $class->SUPER::new($options);
$self->init_v4_signer;
return $self;
}
lib/Amazon/SQS/Client.pm view on Meta::CPAN
}
########################################################################
sub init_v4_signer {
########################################################################
my ($self) = @_;
return
if $self->get_SignatureVersion ne '4';
my $credentials = $self->get_credentials;
my $aws_access_key_id = $credentials->get_aws_access_key_id;
my $aws_secret_access_key = $credentials->get_aws_secret_access_key;
my $token = $credentials->get_token;
require AWS::Signature4;
$self->set_v4_signer(
AWS::Signature4->new(
'-access_key' => $aws_access_key_id,
'-secret_key' => $aws_secret_access_key,
$token
? ( '-security_token' => $token )
: ()
)
);
return;
}
# setter/getters for resetting credentials
########################################################################
sub aws_access_key_id {
########################################################################
my ( $self, @args ) = @_;
if (@args) {
$self->get_credentials->set_aws_access_key_id( $args[0] );
}
return $self->get_credentials->get_aws_access_key_id();
}
########################################################################
sub aws_secret_access_key {
########################################################################
my ( $self, @args ) = @_;
if (@args) {
$self->get_credentials->set_aws_secret_access_key( $args[0] );
}
return $self->get_credentials->get_aws_secret_access_key();
}
########################################################################
sub token {
########################################################################
my ( $self, @args ) = @_;
if (@args) {
$self->get_credentials->set_token( $args[0] );
}
return $self->get_credentials->get_token();
}
########################################################################
sub createQueue {
########################################################################
my ( $self, $request ) = @_;
if ( ref $request ne 'Amazon::SQS::Model::CreateQueueRequest' ) {
require Amazon::SQS::Model::CreateQueueRequest;
$request = Amazon::SQS::Model::CreateQueueRequest->new($request);
lib/Amazon/SQS/Client.pm view on Meta::CPAN
return $response;
}
#
# Add authentication related and version parameters
#
sub _addRequiredParameters {
my ( $self, $parameters, $queueUrl ) = @_;
my $credentials = $self->get_credentials;
my $token = $credentials->get_token;
my $aws_access_key_id = $credentials->get_aws_access_key_id;
my $aws_secret_access_key = $credentials->get_aws_secret_access_key;
$parameters->{AWSAccessKeyId} = $aws_access_key_id;
$parameters->{Timestamp} = $self->_getFormattedTimestamp();
$parameters->{Version} = $self->get_ServiceVersion;
# v2 signing
if ( !defined $self->{_v4_signer} ) {
if ($token) {
$parameters->{SecurityToken} = $token;
}
lib/Amazon/SQS/Client.pm view on Meta::CPAN
default: 2
I<Note: Signature Version 4 is supported by AWS::Signature4. If you
use the Signature 4 signing facility, make sure your ServiceURL
includes the region endpoint. Ex:
https://sqs.us-east-1.amazonaws.com.>
=item * SecurityToken
For temporary credentials, add the security token returned from the
AWS Security Token Service.
=item * ServiceVersion
default: 2012-11-05
=item * MaxErrorRetry
default: 3
=item * credentials
An instance of a class (e.g. Amazon::Credentials) which supports the getters:
get_aws_access_key_id
get_aws_secret_access_key
get_token
You are encouraged to use this option rather than sending the
credentials in the constructor.
=back
=back
=head2 createQueue
createQueue( request )
The C<CreateQueue> action creates a new queue, or returns the URL of an
lib/Amazon/SQS/Config.pm view on Meta::CPAN
delay receipt of messages up to the max wait time.
I<NOTE: Using long polling instead of short polling will result in your daemon
blocking until the ReceiveMessage API returns. Signals received during
this period not be may not be immediately acting upon.>
=back
=head2 aws
This section describes the SQS endpoint and your API credentials. By
default, the F<QueueDaemon.pl> script will use the
L<Amazon::Credentials> class to find your credentials so you do not
need to configure them here.
[aws]
access_key_id = <Your Access Key ID>
secret_access_key = <Your Secret Access Key>
endpoint_url = https://sqs.amazonaws.com
=over 5
=item access_key_id
lib/Amazon/SQS/Config.pm view on Meta::CPAN
C<Log::Log4perl> logging level ('trace', 'debug', 'info', 'warn', 'error').
=item file
Name of a log file for C<Log::Log4perl> messages. You can also use the
values of 'stdout' or 'stderr' to log to STDOUT and STDERR.
=back
I<WARNING: You should probably make sure that the F<.ini> file is properly
protected with restrictive permissions if you place credentials in
this file.>
=head1 METHODS AND SUBROUTINES
=head2 new
new( file => filename | handle )
You can pass either the name of a file or a file handle to the new
method. See L<Config::IniFiles>.
lib/Amazon/SQS/QueueHandler.pm view on Meta::CPAN
use Amazon::SQS::Client;
use CGI::Simple;
use JSON;
use List::Util qw(none max);
__PACKAGE__->follow_best_practice;
__PACKAGE__->mk_accessors(
qw(
config
create_queue
credentials
endpoint_url
logger
max_error_retry
message
message_id
message_type
message_body
raw_message
receipt_handle
request
lib/Amazon/SQS/QueueHandler.pm view on Meta::CPAN
our $TRUE = 1;
our $FALSE = 0;
########################################################################
sub new {
########################################################################
my ( $class, @args ) = @_;
my $options = ref $args[0] ? $args[0] : {@args};
$options->{credentials} //= Amazon::Credentials->new;
my $self = $class->SUPER::new($options);
$self->init_defaults();
$self->create_service();
if ( $self->get_name && !$self->get_url ) {
my %queue_list = reverse $self->list_queues();
if ( $self->get_create_queue ) {
lib/Amazon/SQS/QueueHandler.pm view on Meta::CPAN
}
########################################################################
sub create_service {
########################################################################
my ($self) = @_;
my %options = (
ServiceURL => $self->get_endpoint_url,
MaxErrorRetry => $self->get_max_error_retry,
credentials => $self->get_credentials,
);
my $service = eval { return Amazon::SQS::Client->new( undef, undef, \%options ); };
die "could not create service\n$EVAL_ERROR"
if !$service || $EVAL_ERROR;
$self->set_service($service);
return $service;
share/example.pl view on Meta::CPAN
eval { $sample->sample(@ARGV); };
$sample->check_error($EVAL_ERROR);
return 0
if !$options{debug};
print {*STDERR} Dumper(
[ request => $sample->get_service->get_last_request,
response => $sample->get_service->get_last_response,
credentials => $sample->get_service->get_credentials,
]
);
return 0;
}
exit main();
1;
share/example.pl view on Meta::CPAN
--help, -h help
=head2 Configuration File
Some examples may rely on values you must set in your .ini file.
See L<Amazon::SQS::Config> for the format of the .ini file.
=head2 AWS Credentials
You can set your credentials in the config file in the C<[aws]>
section or rely on the L<Amazon::Credentials> to find your credentials
in the environment.
=head2 Running the Examples
To get help for running a specific example:
example.pl -h ListQueues
=head1 AUTHOR