Class WAZ::Queues::Service
In: lib/waz/queues/service.rb
Parent: Object

This is internally used by the waz-queues part of the gem and it exposes the Windows Azure Queue API REST methods implementation. You can use this class to perform an specific operation that aren‘t provided by the current API.

Methods

Included Modules

WAZ::Storage::SharedKeyCoreService

Public Instance methods

Marks every message on the given queue for deletion.

[Source]

     # File lib/waz/queues/service.rb, line 101
101:       def clear_queue(queue_name)
102:         execute :delete, "#{queue_name}/messages", {}, :x_ms_version => '2009-09-19'
103:       end

Creates a queue on the current storage account. Throws WAZ::Queues::QueueAlreadyExists when existing metadata and given metadata differ.

[Source]

    # File lib/waz/queues/service.rb, line 33
33:       def create_queue(queue_name, metadata = {})
34:         execute(:put, queue_name, nil, metadata.merge!(:x_ms_version => '2009-09-19'))
35:       end

Deletes the given message from the queue, correlating the operation with the pop_receipt in order to avoid eventually inconsistent scenarios.

[Source]

    # File lib/waz/queues/service.rb, line 96
96:       def delete_message(queue_name, message_id, pop_receipt)
97:         execute :delete, "#{queue_name}/messages/#{message_id}", { :pop_receipt => pop_receipt }
98:       end

Deletes the given queue from the current storage account.

[Source]

    # File lib/waz/queues/service.rb, line 38
38:       def delete_queue(queue_name)
39:         execute(:delete, queue_name, {}, {:x_ms_version => '2009-09-19'})
40:       end

Enqueues a message on the current queue.

ttl Specifies the time-to-live interval for the message, in seconds. The maximum time-to-live allowed is 7 days. If this parameter is omitted, the default time-to-live is 7 days.

[Source]

    # File lib/waz/queues/service.rb, line 56
56:       def enqueue(queue_name, message_payload, ttl = 604800)
57:         payload = "<?xml version=\"1.0\" encoding=\"utf-8\"?><QueueMessage><MessageText>#{message_payload}</MessageText></QueueMessage>"
58:         execute(:post, "#{queue_name}/messages", { :messagettl => ttl }, { 'Content-Type' => 'application/xml', :x_ms_version => "2009-09-19"}, payload)
59:       end

Locks N messages (1 default) from the given queue.

:num_of_messages option specifies the max number of messages to get (maximum 32)

:visibility_timeout option specifies the timeout of the message locking in seconds (max two hours)

[Source]

    # File lib/waz/queues/service.rb, line 66
66:       def get_messages(queue_name, options = {})
67:         raise WAZ::Queues::OptionOutOfRange, {:name => :num_of_messages, :min => 1, :max => 32} if (options.keys.include?(:num_of_messages) && (options[:num_of_messages].to_i < 1 || options[:num_of_messages].to_i > 32))
68:         raise WAZ::Queues::OptionOutOfRange, {:name => :visibility_timeout, :min => 1, :max => 7200} if (options.keys.include?(:visibility_timeout) && (options[:visibility_timeout].to_i < 1 || options[:visibility_timeout].to_i > 7200))
69:         content = execute(:get, "#{queue_name}/messages", options, {:x_ms_version => "2009-09-19"})
70:         doc = REXML::Document.new(content)
71:         messages = []
72:         REXML::XPath.each(doc, '//QueueMessage/') do |item|
73:           message = { :message_id => REXML::XPath.first(item, "MessageId").text,
74:                       :message_text => REXML::XPath.first(item, "MessageText").text,
75:                       :dequeue_count => REXML::XPath.first(item, "DequeueCount").nil? ? nil : REXML::XPath.first(item, "DequeueCount").text.to_i,
76:                       :expiration_time => Time.httpdate(REXML::XPath.first(item, "ExpirationTime").text),
77:                       :insertion_time => Time.httpdate(REXML::XPath.first(item, "InsertionTime").text) }
78: 
79:           # This are only valid when peek-locking messages
80:           message[:pop_receipt] = REXML::XPath.first(item, "PopReceipt").text unless REXML::XPath.first(item, "PopReceipt").nil?
81:           message[:time_next_visible] = Time.httpdate(REXML::XPath.first(item, "TimeNextVisible").text) unless REXML::XPath.first(item, "TimeNextVisible").nil?
82:           messages << message
83:         end
84:         return messages
85:       end

Gets the given queue metadata.

[Source]

    # File lib/waz/queues/service.rb, line 43
43:       def get_queue_metadata(queue_name)
44:         execute(:head, queue_name, { :comp => 'metadata'}, :x_ms_version => '2009-09-19').headers
45:       end

Lists the queues on the given storage account.

When the options :include => ‘metadata’ is passed it returns the corresponding metadata for each queue on the listing.

[Source]

    # File lib/waz/queues/service.rb, line 12
12:       def list_queues(options ={})
13:         content = execute(:get, nil, { :comp => 'list' }.merge!(options), { :x_ms_version => "2009-09-19" })
14:         doc = REXML::Document.new(content)
15:         queues = []
16:         
17:         REXML::XPath.each(doc, '//Queue/') do |item|
18:           metadata = {}
19:           
20:           item.elements['Metadata'].elements.each do |element|
21:             metadata.merge!(element.name.gsub(/-/, '_').downcase.to_sym => element.text)
22:           end unless item.elements['Metadata'].nil?
23:           
24:           queues << { :name => REXML::XPath.first(item, "Name").text,
25:                       :url => REXML::XPath.first(item, "Url").text,
26:                       :metadata => metadata}
27:         end
28:         return queues
29:       end

Peeks N messages (default 1) from the given queue.

Implementation is the same of get_messages but differs on an additional parameter called :peek_only.

[Source]

    # File lib/waz/queues/service.rb, line 90
90:       def peek(queue_name, options = {})
91:         return get_messages(queue_name, {:peek_only => true}.merge(options))
92:       end

Sets the given queue metadata.

[Source]

    # File lib/waz/queues/service.rb, line 48
48:       def set_queue_metadata(queue_name, metadata = {})
49:         execute(:put, queue_name, { :comp => 'metadata' }, metadata.merge!(:x_ms_version => '2009-09-19'))
50:       end

[Validate]