Class WAZ::Queues::Message
In: lib/waz/queues/message.rb
Parent: Object

This class is used to model a Message inside Windows Azure Queues the usage it‘s pretty simple, here you can see a couple of samples. Messages consist on an UTF-8 string up-to 8KB and some metadata regarding its status and visibility. Here are all the things that you can do with a message:

 message.message_id #=> returns message id

 # this is the most important method regarding messages
 message.message_text #=> returns message contents

 message.pop_receipt #=> used for correlating your dequeue request + a delete operation

 message.expiration_time #=> returns when the message will be removed from the queue

 message.time_next_visible #=> when the message will be visible to other users

 message.insertion_time #=> when the message will be visible to other users

 message.queue_name #=> returns the queue name where the message belongs

 # remove the message from the queue
 message.destroy!

Methods

Attributes

dequeue_count  [RW] 
expiration_time  [RW] 
insertion_time  [RW] 
message_id  [RW] 
message_text  [RW] 
pop_receipt  [RW] 
time_next_visible  [RW] 

Public Class methods

Creates an instance of Message class, this method is intended to be used internally from the Queue.

[Source]

    # File lib/waz/queues/message.rb, line 40
40:       def initialize(params = {})
41:         self.message_id = params[:message_id]
42:         self.message_text = params[:message_text]
43:         self.pop_receipt = params[:pop_receipt] 
44:         self.expiration_time = params[:expiration_time]
45:         self.insertion_time = params[:insertion_time]
46:         self.time_next_visible = params[:time_next_visible]
47:         self.dequeue_count = params[:dequeue_count]
48:         @queue_name = params[:queue_name]
49:       end

This method is internally used by this class. It‘s the way we keep a single instance of the service that wraps the calls the Windows Azure Queues API. It‘s initialized with the values from the default_connection on WAZ::Storage::Base initialized thru establish_connection!

[Source]

    # File lib/waz/queues/message.rb, line 30
30:         def service_instance
31:           options = WAZ::Storage::Base.default_connection.merge(:type_of_service => "queue")
32:           (@service_instances ||= {})[options[:account_name]] ||= Service.new(options)
33:         end

Public Instance methods

Marks the message for deletion (to later be removed from the queue by the garbage collector). If the message where the message is being actually called was peeked from the queue instead of locked it will raise the WAZ::Queues:InvalidOperation exception since it‘s not a permited operation.

[Source]

    # File lib/waz/queues/message.rb, line 59
59:       def destroy!
60:         raise WAZ::Queues::InvalidOperation if pop_receipt.nil?
61:         self.class.service_instance.delete_message(queue_name, message_id, pop_receipt)
62:       end

Returns the Queue name where the Message belongs to

[Source]

    # File lib/waz/queues/message.rb, line 52
52:       def queue_name
53:         return @queue_name
54:       end

[Validate]