Class: AWS::SQS::QueueCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/aws/sqs/queue_collection.rb

Overview

Represents all the Queue objects in your account.

If you have permission to access a queue created by another account, you can also use this collection to access that queue by URL.

Examples:

Printing the URLs of all queues

pp sqs.queues.map(&:url)

Filtering queues by queue name prefix

pp sqs.queues.with_prefix("production_").map(&:url)

Accessing a queue by URL

url = "http://sqs.us-east-1.amazonaws.com/123456789012/myqueue"
sqs.queues[url].send_message("HELLO")

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#prefixString (readonly)

Returns The queue name prefix by which this collection is filtered.

Returns:

  • (String)

    The queue name prefix by which this collection is filtered.



48
49
50
# File 'lib/aws/sqs/queue_collection.rb', line 48

def prefix
  @prefix
end

Instance Method Details

#[](url) ⇒ Queue

Returns The queue with the given URL.

Returns:

  • (Queue)

    The queue with the given URL.



98
99
100
# File 'lib/aws/sqs/queue_collection.rb', line 98

def [](url)
  Queue.new(url, :config => config)
end

#create(name, opts = {}) ⇒ Queue

Note:

If you delete a queue, you must wait at least 60 seconds before creating a queue with the same name.

Creates a new queue.

Parameters:

  • name (String)

    The name to use for the queue created. Constraints: Maximum 80 characters; alphanumeric characters, hyphens (-), and underscores (_) are allowed.

    To successfully create a new queue, you must provide a name that is unique within the scope of your own queues. If you provide the name of an existing queue, a new queue isn’t created and an error isn’t returned. Instead, the request succeeds and the queue URL for the existing queue is returned. Exception: if you provide a value for :default_visibility_timeout that is different from the value for the existing queue, you receive an error.

  • opts (Hash) (defaults to: {})

    Additional options for creating the queue.

Options Hash (opts):

  • :default_visibility_timeout (Integer)

    The visibility timeout (in seconds) to use for this queue.

Returns:

  • (Queue)

    The newly created queue.



77
78
79
80
# File 'lib/aws/sqs/queue_collection.rb', line 77

def create(name, opts = {})
  resp = client.create_queue(opts.merge(:queue_name => name))
  Queue.new(resp.queue_url, :config => config)
end

#each {|queue| ... } ⇒ Object

Yield Parameters:



83
84
85
86
87
88
# File 'lib/aws/sqs/queue_collection.rb', line 83

def each(&block)
  client.list_queues.queue_urls.each do |url|
    queue = self[url]
    yield(queue)
  end
end

#with_prefix(prefix) ⇒ QueueCollection

Returns A new collection representing only the queues whose names start with the given prefix.

Parameters:

  • prefix (String)

    The queue name prefix.

Returns:

  • (QueueCollection)

    A new collection representing only the queues whose names start with the given prefix.



93
94
95
# File 'lib/aws/sqs/queue_collection.rb', line 93

def with_prefix(prefix)
  self.class.new(:prefix => prefix, :config => config)
end