Class RightAws::Sqs::Queue
In: lib/sqs/right_sqs.rb
Parent: Object

Methods

Attributes

name  [R] 
sqs  [R] 
url  [R] 

Public Class methods

Returns Queue instance by queue name. If the queue does not exist at Amazon SQS and create is true, the method creates it.

 RightAws::Sqs::Queue.create(sqs, 'my_awesome_queue') #=> #<RightAws::Sqs::Queue:0xb7b626e4 ... >

Creates new Queue instance. Does not create a queue at Amazon.

 queue = RightAws::Sqs::Queue.new(sqs, 'my_awesome_queue')

Public Instance methods

Clears queue. Deletes only the visible messages unless force is true.

 queue.clear(true) #=> true

P.S. when force==true the queue deletes then creates again. This is the quickest method to clear a big queue or a queue with ‘locked’ messages. All queue attributes are restored. But there is no way to restore grantees’ permissions to this queue. If you have no grantees except ‘root’ then you have no problems. Otherwise, it‘s better to use queue.clear(false).

PS This function is no longer supported. Amazon has changed the SQS semantics to require at least 60 seconds between queue deletion and creation. Hence this method will fail with an exception.

Deletes queue. Queue must be empty or force must be set to true. Returns true.

 queue.delete(true) #=> true

Retrieves queue attributes. At this moment Amazon supports VisibilityTimeout and ApproximateNumberOfMessages only. If the name of attribute is set, returns its value. Otherwise, returns a hash of attributes.

queue.get_attribute(‘VisibilityTimeout’) #=> ‘100‘

Retrieves a list of grantees. Returns an array of Grantee instances if the grantee_email_address is unset. Otherwise returns a Grantee instance that points to grantee_email_address or nil.

 grantees = queue.grantees #=> [#<RightAws::Sqs::Grantee:0xb7bf0888 ... >, ...]
  ...
 grantee  = queue.grantees('cool_guy@email.address') #=> nil | #<RightAws::Sqs::Grantee:0xb7bf0888 ... >

Peeks message body.

 queue.peek #=> #<RightAws::Sqs::Message:0xb7bf0884 ... >

Pops (and deletes) first accessible message from queue. Returns Message instance or nil it the queue is empty.

 queue.pop #=> #<RightAws::Sqs::Message:0xb7bf0884 ... >
push(message)

Alias for send_message

Retrieves first accessible message from queue. Returns Message instance or nil it the queue is empty.

 queue.receive #=> #<RightAws::Sqs::Message:0xb7bf0884 ... >

Retrieves several messages from queue. Returns an array of Message instances.

 queue.receive_messages(2,10) #=> array of messages

Sends new message to queue. Returns new Message instance that has been sent to queue.

Sets new queue attribute value. Not all attributes may be changed: ApproximateNumberOfMessages (for example) is a read only attribute. Returns a value to be assigned to attribute.

queue.set_attribute(‘VisibilityTimeout’, ‘100’) #=> ‘100’ queue.get_attribute(‘VisibilityTimeout’) #=> ‘100‘

Retrieves queue size.

 queue.size #=> 1

Retrieves VisibilityTimeout value for the queue. Returns new timeout value.

 queue.visibility #=> 30

Sets new VisibilityTimeout for the queue. Returns new timeout value.

 queue.visibility #=> 30
 queue.visibility = 33
 queue.visibility #=> 33

[Validate]