Amazon-SQS-Client

 view release on metacpan or  search on metacpan

bin/create-queue.pl  view on Meta::CPAN


  return map { /([^\/]+)$/xsm ? ( "$1" => $_ ) : () } @{$queue_list};
}

########################################################################
sub get_queue_url {
########################################################################
  my ( $client, $options ) = @_;

  my %queue_names = get_queue_names( $client, $options );

  return $queue_names{ $options->{queue} };
}

########################################################################
sub get_queue_attributes {
########################################################################
  my ( $client, $queue_url ) = @_;

  my $rslt = $client->getQueueAttributes(
    { QueueUrl      => $queue_url,
      AttributeName => ['All'],
    }
  );

  my $attributesResult = $rslt->getGetQueueAttributesResult;

  return $attributesResult->getAttribute;
}

########################################################################
sub get_queue_arn {
########################################################################
  my ( $client, $queue_url ) = @_;

  my $attributes = get_queue_attributes( $client, $queue_url );

  my ($arn) = grep {/arn/xsmi} map { $_->getValue } @{$attributes};

  die "could not find queue ($queue_url) arn\n"
    if !$arn;

  return $arn;
}

########################################################################
sub create_dlq {
########################################################################
  my ( $client, $options ) = @_;

  my $name = $options->{queue};

  my $dlq = $name . 'DLQ';

  my $redriveAllowPolicy = { redrivePermission => 'allowAll' };

  my @attributes = (
    { Name  => 'RedriveAllowPolicy',
      Value => JSON->new->encode($redriveAllowPolicy)
    },
    { Name  => 'VisibilityTimeout',
      Value => $options->{'visibility-timeout'},
    },
  );

  local $options->{queue} = $dlq;

  return create_queue( $client, $options, @attributes );
}

########################################################################
sub create_test_queue {
########################################################################
  my ( $client, %options ) = @_;

  my $dlq_url = $options{dlq_url};

  if ($dlq_url) {

    $options{'redrive-policy'} = JSON->new->encode(
      { deadLetterTargetArn => get_queue_arn( $client, $dlq_url ),
        maxReceiveCount     => $options{'max-receive-count'},
      }
    );
  }

  my @attribute_names = qw(
    delay-seconds
    maximum-message-size
    message-retention-period
    redrive-policy
    visibility-timeout
    receive-message-wait-time-seconds
  );

  my @attributes = map { { Name => toCamelCase($_), Value => $options{$_} } } @attribute_names;

  return create_queue( $client, \%options, @attributes );
}

########################################################################
sub toCamelCase {
########################################################################
  my ($var) = @_;

  return join q{}, map { ucfirst $_ } split /[\-]/xsm, $var;
}

########################################################################
sub create_test_queues {
########################################################################
  my ( $client, $options ) = @_;

  my $dlq_url;

  if ( $options->{dlq} ) {
    $dlq_url = create_dlq( $client, $options );
  }

  my $url = create_test_queue( $client, dlq_url => $dlq_url, %{$options} );

bin/create-queue.pl  view on Meta::CPAN


=item delete-message - delete a message

 delete-message receipt-handle

=back

=head1 OPTIONS

 --help, -h

 --queue, -q 

 Queue name. The dead letter queue will be the same name with a DLQ suffix

 --endpoint-url, -e  

 Endpoint URL Default: https://queue.amazonaws.com

 --delay-seconds, -D

 Length of time, in seconds, for which the delivery of all messages in
 the queue is delayed. Valid values: An integer from 0 to 900 seconds
 (15 minutes). Default: 0.

 --maximum-message-size, -M 

 The limit of how many bytes a message can contain before Amazon SQS
 rejects it. Valid values: An integer from 1,024 bytes (1 KiB) to
 262,144 bytes (256 KiB). Default: 262,144 (256 KiB).

 --max-receive-count, -c

 The number of times a message is delivered to the source queue before
 being moved to the dead-letter queue. Default: 10. When the
 ReceiveCount for a message exceeds the maxReceiveCount for a queue,
 Amazon SQS moves the message to the dead-letter-queue.

 --message-retention-period, -p

 The length of time, in seconds, for which Amazon SQS retains a
 message.  Valid values: An integer from 60 seconds (1 minute) to
 1,209,600 seconds (14 days). Default: 345,600 (4 days). When you
 change a queue's attributes, the change can take up to 60 seconds for
 most of the attributes to propagate throughout the Amazon SQS
 system. Changes made to the MessageRetentionPeriod attribute can take
 up to 15 minutes and will impact existing messages in the queue
 potentially causing them to be expired and deleted if the
 MessageRetentionPeriod is reduced below the age of existing messages.

 --receive-message-wait-time_seconds, -w

 The length of time, in seconds, for which a ReceiveMessage action
 waits for a message to arrive. Valid values: An integer from 0 to 20
 (seconds). Default: 0.

 --visibility-timeout, -v

 The visibility timeout for the queue, in seconds. Valid values: An
 integer from 0 to 43,200 (12 hours). Default: 30. For more
 information about the visibility timeout, see Visibility Timeout in
 the Amazon SQS Developer Guide.

=head2 AUTHOR

Rob Lauer - <bigfoot@cpan.org>

=cut



( run in 1.344 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )