Class: FreeMessageQueue::FileQueue

Inherits:
BaseQueue
  • Object
show all
Defined in:
lib/fmq/queues/file.rb

Overview

This queue returns everytime the same file. This is useful during debugging or to serve the admin page.

queue_manager = FreeMessageQueue::QueueManager.new(true) do
  setup_queue "/dummy/file", FreeMessageQueue::FileQueue do |q|
    q.file = "tmp/default_message.yml"
    q.content_type = "text/yaml"
  end
end

NOTE the put method is not implemented in this queue. It is a poll only queue.

Constant Summary

Constants inherited from BaseQueue

BaseQueue::INFINITE

Instance Attribute Summary

Attributes inherited from BaseQueue

#bytes, #manager, #max_messages, #max_size, #size

Instance Method Summary collapse

Methods inherited from BaseQueue

#empty?, #initialize

Constructor Details

This class inherits a constructor from FreeMessageQueue::BaseQueue

Instance Method Details

#content_type=(type) ⇒ Object

CONFIGURATION OPTION sets the content_type of the file. This option make sense if you want to test with the webbrowser.



54
55
56
# File 'lib/fmq/queues/file.rb', line 54

def content_type=(type)
  @content_type = type
end

#file=(path) ⇒ Object

CONFIGURATION OPTION sets the path to the file that should be read



47
48
49
# File 'lib/fmq/queues/file.rb', line 47

def file=(path)
  @file_path = path
end

#pollObject

Return the file and content type



35
36
37
38
39
40
41
42
43
# File 'lib/fmq/queues/file.rb', line 35

def poll()
  file_content = ""
  File.open(@file_path, "rb") do |f|
    file_content = f.read
  end
  
  @bytes = file_content.size
  Message.new(file_content, @content_type)
end