Class: Aws::SQS::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-sdk-sqs/resource.rb

Overview

This class provides a resource oriented interface for SQS. To create a resource object:

resource = Aws::SQS::Resource.new(region: 'us-west-2')

You can supply a client object with custom configuration that will be used for all resource operations. If you do not pass `:client`, a default client will be constructed.

client = Aws::SQS::Client.new(region: 'us-west-2')
resource = Aws::SQS::Resource.new(client: client)

Actions collapse

Associations collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Resource

Returns a new instance of Resource.

Parameters:

  • options ({}) (defaults to: {})

Options Hash (options):


27
28
29
# File 'lib/aws-sdk-sqs/resource.rb', line 27

def initialize(options = {})
  @client = options[:client] || Client.new(options)
end

Instance Method Details

#clientClient

Returns:


32
33
34
# File 'lib/aws-sdk-sqs/resource.rb', line 32

def client
  @client
end

#create_queue(options = {}) ⇒ Queue

Examples:

Request syntax with placeholder values


queue = sqs.create_queue({
  queue_name: "String", # required
  attributes: {
    "All" => "String",
  },
  tags: {
    "TagKey" => "TagValue",
  },
})

Parameters:

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

    ({})

Options Hash (options):

Returns:


262
263
264
265
266
267
268
# File 'lib/aws-sdk-sqs/resource.rb', line 262

def create_queue(options = {})
  resp = @client.create_queue(options)
  Queue.new(
    url: resp.data.queue_url,
    client: @client
  )
end

#get_queue_by_name(options = {}) ⇒ Queue

Examples:

Request syntax with placeholder values


queue = sqs.get_queue_by_name({
  queue_name: "String", # required
  queue_owner_aws_account_id: "String",
})

Parameters:

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

    ({})

Options Hash (options):

  • :queue_name (required, String)

    The name of the queue whose URL must be fetched. Maximum 80 characters. Valid values: alphanumeric characters, hyphens (`-`), and underscores (`_`).

    Queue URLs and names are case-sensitive.

  • :queue_owner_aws_account_id (String)

    The Amazon Web Services account ID of the account that created the queue.

Returns:


287
288
289
290
291
292
293
# File 'lib/aws-sdk-sqs/resource.rb', line 287

def get_queue_by_name(options = {})
  resp = @client.get_queue_url(options)
  Queue.new(
    url: resp.data.queue_url,
    client: @client
  )
end

#queue(url) ⇒ Queue

Parameters:

  • url (String)

Returns:


299
300
301
302
303
304
# File 'lib/aws-sdk-sqs/resource.rb', line 299

def queue(url)
  Queue.new(
    url: url,
    client: @client
  )
end

#queues(options = {}) ⇒ Queue::Collection

Examples:

Request syntax with placeholder values


queues = sqs.queues({
  queue_name_prefix: "String",
})

Parameters:

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

    ({})

Options Hash (options):

  • :queue_name_prefix (String)

    A string to use for filtering the list results. Only those queues whose name begins with the specified string are returned.

    Queue URLs and names are case-sensitive.

Returns:


318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/aws-sdk-sqs/resource.rb', line 318

def queues(options = {})
  batches = Enumerator.new do |y|
    resp = @client.list_queues(options)
    resp.each_page do |page|
      batch = []
      page.data.queue_urls.each do |q|
        batch << Queue.new(
          url: q,
          client: @client
        )
      end
      y.yield(batch)
    end
  end
  Queue::Collection.new(batches)
end