Class | RightAws::SqsGen2Interface |
In: |
lib/sqs/right_sqs_gen2_interface.rb
|
Parent: | RightAwsBase |
Right::Aws::SqsGen2Interface - RightScale‘s low-level Amazon SQS interface for API version 2008-01-01 and later. For explanations of the semantics of each call, please refer to Amazon‘s documentation at developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=31
This class provides a procedural interface to SQS. Conceptually it is mostly a pass-through interface to SQS and its API is very similar to the bare SQS API. For a somewhat higher-level and object-oriented interface, see RightAws::SqsGen2.
SIGNATURE_VERSION | = | "1" |
API_VERSION | = | "2008-01-01" |
DEFAULT_HOST | = | "queue.amazonaws.com" |
DEFAULT_PORT | = | 443 |
DEFAULT_PROTOCOL | = | 'https' |
REQUEST_TTL | = | 30 |
DEFAULT_VISIBILITY_TIMEOUT | = | 30 |
Creates a new SqsInterface instance. This instance is limited to operations on SQS objects created with Amazon‘s 2008-01-01 API version. This interface will not work on objects created with prior API versions. See Amazon‘s article "Migrating to Amazon SQS API version 2008-01-01" at: developer.amazonwebservices.com/connect/entry.jspa?externalID=1148
sqs = RightAws::SqsGen2Interface.new('1E3GDYEOGFJPIT75KDT40','hgTHt68JY07JKUY08ftHYtERkjgtfERn57DFE379', {:multi_thread => true, :logger => Logger.new('/tmp/x.log')})
Params is a hash:
{:server => 'queue.amazonaws.com' # Amazon service host: 'queue.amazonaws.com' (default) :port => 443 # Amazon service port: 80 or 443 (default) :multi_thread => true|false # Multi-threaded (connection per each thread): true or false (default) :signature_version => '0' # The signature version : '0' or '1'(default) :logger => Logger Object} # Logger instance: logs to STDOUT if omitted }
Returns short queue name by url.
RightSqs.queue_name_by_url('http://queue.amazonaws.com/ZZ7XXXYYYBINS/my_awesome_queue') #=> 'my_awesome_queue'
Removes all visible messages from queue. Return true or an exception.
sqs.clear_queue('http://queue.amazonaws.com/ZZ7XXXYYYBINS/my_awesome_queue') #=> true
Creates a new queue, returning its URI.
sqs.create_queue('my_awesome_queue') #=> 'http://queue.amazonaws.com/ZZ7XXXYYYBINS/my_awesome_queue'
Deletes message from queue. Returns true or an exception. Amazon returns true on deletion of non-existent messages. You must use the receipt handle for a message to delete it, not the message ID.
From the SQS Developer Guide: "It is possible you will receive a message even after you have deleted it. This might happen on rare occasions if one of the servers storing a copy of the message is unavailable when you request to delete the message. The copy remains on the server and might be returned to you again on a subsequent receive request. You should create your system to be idempotent so that receiving a particular message more than once is not a problem. "
sqs.delete_message('http://queue.amazonaws.com/ZZ7XXXYYYBINS/my_awesome_queue', 'Euvo62/1nlIet...ao03hd9Sa0w==') #=> true
Deletes queue. Any messages in the queue are permanently lost. Returns true or an exception. Queue deletion can take up to 60 s to propagate through SQS. Thus, after a deletion, subsequent list_queues calls may still show the deleted queue. It is not unusual within the 60 s window to see the deleted queue absent from one list_queues call but present in the subsequent one. Deletion is eventual.
sqs.delete_queue('http://queue.amazonaws.com/ZZ7XXXYYYBINS/my_awesome_queue_2') #=> true
Retrieves the queue attribute(s). Returns a hash of attribute(s) or an exception.
sqs.get_queue_attributes('http://queue.amazonaws.com/ZZ7XXXYYYBINS/my_awesome_queue') #=> {"ApproximateNumberOfMessages"=>"0", "VisibilityTimeout"=>"30"}
Returns approximate number of messages in queue.
sqs.get_queue_length('http://queue.amazonaws.com/ZZ7XXXYYYBINS/my_awesome_queue') #=> 3
Lists all queues owned by this user that have names beginning with queue_name_prefix. If queue_name_prefix is omitted then retrieves a list of all queues. Queue creation is an eventual operation and created queues may not show up in immediately subsequent list_queues calls.
sqs.create_queue('my_awesome_queue') sqs.create_queue('my_awesome_queue_2') sqs.list_queues('my_awesome') #=> ['http://queue.amazonaws.com/ZZ7XXXYYYBINS/my_awesome_queue','http://queue.amazonaws.com/ZZ7XXXYYYBINS/my_awesome_queue_2']
Pops (retrieves and deletes) first accessible message from queue. Returns the message in format {:id=>’message_id’, :body=>’message_body’} or nil.
sqs.pop_message('http://queue.amazonaws.com/ZZ7XXXYYYBINS/my_awesome_queue') #=> {:id=>"12345678904GEZX9746N|0N9ED344VK5Z3SV1DTM0|1RVYH4X3TJ0987654321", :body=>"message_1"}
Pops (retrieves and deletes) up to ‘number_of_messages’ from queue. Returns an array of retrieved messages in format: [{:id=>’message_id’, :body=>’message_body’}].
sqs.pop_messages('http://queue.amazonaws.com/ZZ7XXXYYYBINS/my_awesome_queue', 3) #=> [{"ReceiptHandle"=>"Euvo62/...+Zw==", "MD5OfBody"=>"16af2...81e3", "Body"=>"Goodbyte World!", "MessageId"=>"MEZI...JSWDE="}, {...}, ... , {...} ]
Returns short queue name by url.
sqs.queue_name_by_url('http://queue.amazonaws.com/ZZ7XXXYYYBINS/my_awesome_queue') #=> 'my_awesome_queue'
Given the queue‘s short name, this call returns the queue URL or nil if queue is not found
sqs.queue_url_by_name('my_awesome_queue') #=> 'http://queue.amazonaws.com/ZZ7XXXYYYBINS/my_awesome_queue'
Retrieves a list of messages from queue. Returns an array of hashes in format: {:id=>’message_id’, body=>’message_body’}
sqs.receive_message('http://queue.amazonaws.com/ZZ7XXXYYYBINS/my_awesome_queue',10, 5) #=> [{"ReceiptHandle"=>"Euvo62...kw==", "MD5OfBody"=>"16af2171b5b83cfa35ce254966ba81e3", "Body"=>"Goodbyte World!", "MessageId"=>"MUM4WlAyR...pYOTA="}, ..., {}]
Normally this call returns fewer messages than the maximum specified, even if they are available.
Sends a new message to a queue. Message size is limited to 8 KB. If successful, this call returns a hash containing key/value pairs for "MessageId" and "MD5OfMessageBody":
sqs.send_message('http://queue.amazonaws.com/ZZ7XXXYYYBINS/my_awesome_queue', 'message_1') #=> "1234567890...0987654321" => {"MessageId"=>"MEs4M0JKNlRCRTBBSENaMjROTk58QVFRNzNEREhDVFlFOVJDQ1JKNjF8UTdBRllCUlJUMjhKMUI1WDJSWDE=", "MD5OfMessageBody"=>"16af2171b5b83cfa35ce254966ba81e3"}
On failure, send_message raises an exception.
Sets queue attribute. Returns true or an exception.
sqs.set_queue_attributes('http://queue.amazonaws.com/ZZ7XXXYYYBINS/my_awesome_queue', "VisibilityTimeout", 10) #=> true
From the SQS Dev Guide: "Currently, you can set only the VisibilityTimeout attribute for a queue… When you change a queue‘s attributes, the change can take up to 60 seconds to propagate throughout the SQS system."
NB: Attribute values may not be immediately available to other queries for some time after an update. See the SQS documentation for semantics, but in general propagation can take up to 60 s.