Class: FreeMessageQueue::FilePersistentQueue
- Defined in:
- lib/fmq/queues/file_persistent.rb
Overview
This a FIFO queue that stores messages in the file system
queue_manager = FreeMessageQueue::QueueManager.new(true) do
setup_queue "/mail_box/threez", FreeMessageQueue::FilePersistentQueue do |q|
q.folder = "./tmp/mail_box/threez"
q. = 10000
end
end
NOTE the put method is not implemented in this queue. It is a poll only queue.
Constant Summary
Constants inherited from BaseQueue
Instance Attribute Summary
Attributes inherited from BaseQueue
#bytes, #manager, #max_messages, #max_size, #size
Instance Method Summary collapse
-
#clear ⇒ Object
remove all items from the queue.
-
#folder=(path) ⇒ Object
CONFIGURATION OPTION sets the path to the folder that holds all messages, this will create the folder if it doesn’t exist.
-
#poll ⇒ Object
Return the.
-
#put(message) ⇒ Object
add one message to the queue (will be saved in file system).
Methods inherited from BaseQueue
Constructor Details
This class inherits a constructor from FreeMessageQueue::BaseQueue
Instance Method Details
#clear ⇒ Object
remove all items from the queue
68 69 70 71 72 |
# File 'lib/fmq/queues/file_persistent.rb', line 68 def clear FileUtils.rm @size = 0 @bytes = 0 end |
#folder=(path) ⇒ Object
CONFIGURATION OPTION sets the path to the folder that holds all messages, this will create the folder if it doesn’t exist
62 63 64 65 |
# File 'lib/fmq/queues/file_persistent.rb', line 62 def folder=(path) FileUtils.mkdir_p path unless File.exist? path @folder_path = path end |
#poll ⇒ Object
Return the
35 36 37 38 39 40 41 42 43 |
# File 'lib/fmq/queues/file_persistent.rb', line 35 def poll() check_folder_name = .sort! return nil if .size == 0 msg_bin = File.open(.first, "rb") { |f| f.read } FileUtils.rm .first (Marshal.load(msg_bin)) end |
#put(message) ⇒ Object
add one message to the queue (will be saved in file system)
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fmq/queues/file_persistent.rb', line 46 def put() check_folder_name return false if .nil? () # check constraints and update stats msg_bin = Marshal.dump() File.open(@folder_path + "/#{Time.now.to_f}.msg", "wb") do |f| f.write msg_bin end return true end |