Change order of policy creation for dead lettering
This should prevent messages sitting in the dead letter queue without a ttl.
MODIFY
lib/beetle/queue_properties.rb
lib/beetle/queue_properties.rb
@@ -23,12 +23,17 @@ module Beetle
dead_letter_queue_name = options[:dead_letter_queue_name]
policy_options = options.slice(:lazy, :dead_lettering)
+ # The order of policy creation is important.
+ # We need to create the policy on the dead letter queue first to have the message_ttl setting
+ # in place before the first message comes in. Otherwise a message will not get a ttl
+ # applied and stay in the dead letter queue forever (or until manually consumed), thus
+ # blocking the head of the queue.
+ dead_letter_queue_options = policy_options.merge(:routing_key => target_queue, :message_ttl => options[:message_ttl])
+ set_queue_policy!(server, dead_letter_queue_name, dead_letter_queue_options)
target_queue_options = policy_options.merge(:routing_key => dead_letter_queue_name)
set_queue_policy!(server, target_queue, target_queue_options)
- remove_obsolete_bindings(server, target_queue, options[:bindings]) if options.has_key?(:bindings)
- dead_letter_queue_options = policy_options.merge(:routing_key => target_queue, :message_ttl => options[:message_ttl])
- set_queue_policy!(server, dead_letter_queue_name, dead_letter_queue_options)
+ remove_obsolete_bindings(server, target_queue, options[:bindings]) if options.has_key?(:bindings)
end
def set_queue_policy!(server, queue_name, options={})

MODIFY
test/beetle/queue_properties_test.rb
test/beetle/queue_properties_test.rb
@@ -28,13 +28,15 @@ module Beetle
:queue_name => "QUEUE_NAME", :dead_letter_queue_name => "QUEUE_NAME_dead_letter",
:message_ttl => 10000
}
- @queue_properties.expects(:set_queue_policy!).with("server", "QUEUE_NAME",
- :lazy => true, :dead_lettering => true,
- :routing_key => "QUEUE_NAME_dead_letter")
- @queue_properties.expects(:set_queue_policy!).with("server", "QUEUE_NAME_dead_letter",
+
+ policies = sequence('policies')
+ @queue_properties.expects(:set_queue_policy!).in_sequence(policies).with("server", "QUEUE_NAME_dead_letter",
:lazy => true, :dead_lettering => true,
:routing_key => "QUEUE_NAME",
:message_ttl => 10000)
+ @queue_properties.expects(:set_queue_policy!).in_sequence(policies).with("server", "QUEUE_NAME",
+ :lazy => true, :dead_lettering => true,
+ :routing_key => "QUEUE_NAME_dead_letter")
@queue_properties.update_queue_properties!(options)
end

Change order of policy creation for dead lettering

This should prevent messages sitting in the dead letter queue without a ttl.