Skip to content

Commit

Permalink
added new way to setup queues and fixed auto queue bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Landgraf committed Aug 28, 2008
1 parent 3e95a4f commit 9051d9d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
9 changes: 5 additions & 4 deletions lib/fmq/queue_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ class QueueManager

# setup the queue manager using the configuration from the configuration
# file (which is basically a hash)
def initialize(&block)
def initialize(auto_create_queues = true, &block)
@queues = {}
@log = FreeMessageQueue.logger
@auto_create_queues = true
@auto_create_queues = auto_create_queues
instance_eval(&block) if block_given?
end

Expand All @@ -82,7 +82,7 @@ def auto_create_queues?
def setup_queue(path, queue_class = DEFAULT_QUEUE_CLASS, &block)
check_queue_name(path)
queue_object = queue_class.new(self)
queue_object.instance_eval(&block) if block_given?
block.call(queue_object) if block_given?
@queues[path] = queue_object
@log.info("[QueueManager] Create queue '#{path}' {type: #{queue_class}, max_messages: #{queue_object.max_messages}, max_size: #{queue_object.max_size}}")
return queue_object
Expand Down Expand Up @@ -125,7 +125,7 @@ def put(name, message)
unless queue_exists? name
# only auto create queues if it is configured
if auto_create_queues?
create_queue(name)
setup_queue(name)
else
raise QueueManagerException.new("[QueueManager] There is no queue '#{name}'", caller)
end
Expand Down Expand Up @@ -171,3 +171,4 @@ def check_queue_name(name)
end
end
end

3 changes: 2 additions & 1 deletion lib/fmq/queues/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,5 @@ def check_max_messages_constraint(message)
end
end
end
end
end

25 changes: 8 additions & 17 deletions test/test_queue_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,20 @@ class TestQueueManager < Test::Unit::TestCase
DEFAULT_QUEUE_NAME = "/fmq_test/test1"

def setup
FreeMessageQueue.log_level "fatal"
FreeMessageQueue.log_level "info"

@queue_manager = FreeMessageQueue::QueueManager.new()

@queue_manager.setup do |qm|
qm.auto_create_queues = false

qm.setup_queue DEFAULT_QUEUE_NAME do |q|
@queue_manager = FreeMessageQueue::QueueManager.new(false) do
setup_queue DEFAULT_QUEUE_NAME do |q|
q.max_messages = 100
q.max_size = 100.mb
end

qm.setup_queue "/second_test_queue"
qm.setup_queue "/third_test_queue"
setup_queue "/second_test_queue"
setup_queue "/third_test_queue"
end
end

def test_config
# check that the simple config will work
FreeMessageQueue::QueueManager.new()
@queue_manager.setup do |qm|
qm.auto_create_queues = false
end

def test_config
# check if all queues are available
assert_equal 3, @queue_manager.queues.size
[DEFAULT_QUEUE_NAME, "/second_test_queue", "/third_test_queue"].each do |e|
Expand Down Expand Up @@ -84,4 +74,5 @@ def test_creating_and_deleting
@queue_manager.put(url, new_msg("Test"))
}
end
end
end

0 comments on commit 9051d9d

Please sign in to comment.