Skip to content

Commit

Permalink
Add the abillity to add custom headers when publishing an AMQP message
Browse files Browse the repository at this point in the history
Remove unnecessary test
  • Loading branch information
Bjoern Rochel committed Mar 3, 2015
1 parent 2b9e3e6 commit 164a923
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/beetle.rb
Expand Up @@ -34,7 +34,7 @@ class NoMessageSent < Error; end
# AMQP options for queue bindings
QUEUE_BINDING_KEYS = [:key, :no_wait]
# AMQP options for message publishing
PUBLISHING_KEYS = [:key, :mandatory, :immediate, :persistent, :reply_to]
PUBLISHING_KEYS = [:key, :mandatory, :immediate, :persistent, :reply_to, :headers]
# AMQP options for subscribing to queues
SUBSCRIPTION_KEYS = [:ack, :key]

Expand Down
5 changes: 3 additions & 2 deletions lib/beetle/message.rb
Expand Up @@ -92,11 +92,12 @@ def self.publishing_options(opts = {}) #:nodoc:
expires_at = now + (opts[:ttl] || DEFAULT_TTL)
opts = opts.slice(*PUBLISHING_KEYS)
opts[:message_id] = generate_uuid.to_s
opts[:headers] = {
headers = (opts[:headers] ||= {})
headers.merge!(
:format_version => FORMAT_VERSION.to_s,
:flags => flags.to_s,
:expires_at => expires_at.to_s
}
)
opts
end

Expand Down
14 changes: 14 additions & 0 deletions test/beetle/message_test.rb
Expand Up @@ -64,9 +64,23 @@ class EncodingTest < MiniTest::Unit::TestCase

test "the publishing options must only include string values" do
options = Message.publishing_options(:redundant => true, :mandatory => true, :bogus => true)

assert options[:headers].all? {|_, param| param.is_a?(String)}
end

test "the publishing options support adding custom headers" do
options = Message.publishing_options(
:redundant => true,
:headers => {
:sender_id => "SENDER_ID",
:sender_action => "SENDER_ACTION"
}
)

assert_equal "1", options[:headers][:flags]
assert_equal "SENDER_ID", options[:headers][:sender_id]
assert_equal "SENDER_ACTION", options[:headers][:sender_action]
end
end

class KeyManagementTest < MiniTest::Unit::TestCase
Expand Down

0 comments on commit 164a923

Please sign in to comment.