- unify input/output for amqp. This fixes a bug where we amqp:///topic/foo

would register a topic as "/topic/foo" for outputs but "foo" for inputs.
This commit is contained in:
Jordan Sissel 2010-11-11 08:20:13 +00:00
parent 7f4b1192f8
commit 75910bb656

View file

@ -3,18 +3,18 @@ require "amqp" # rubygem 'amqp'
require "mq" # rubygem 'amqp' require "mq" # rubygem 'amqp'
class LogStash::Outputs::Amqp < LogStash::Outputs::Base class LogStash::Outputs::Amqp < LogStash::Outputs::Base
TYPES = [ "fanout", "queue", "topic" ] MQTYPES = [ "fanout", "queue", "topic" ]
def initialize(url, config={}, &block) def initialize(url, config={}, &block)
super super
# Handle path /<type>/<name> # Handle path /<type>/<name>
unused, @type, @name = @url.path.split("/", 3) unused, @mqtype, @name = @url.path.split("/", 3)
if @type == nil or @name == nil if @mqtype == nil or @name == nil
raise "amqp urls must have a path of /<type>/name where <type> is #{TYPES.join(", ")}" raise "amqp urls must have a path of /<type>/name where <type> is #{MQTYPES.join(", ")}"
end end
if !TYPES.include?(@type) if !MQTYPES.include?(@mqtype)
raise "Invalid type '#{@type}' must be one #{TYPES.join(", ")}" raise "Invalid type '#{@mqtype}' must be one #{MQTYPES.join(", ")}"
end end
end # def initialize end # def initialize
@ -23,14 +23,14 @@ class LogStash::Outputs::Amqp < LogStash::Outputs::Base
@mq = MQ.new(@amqp) @mq = MQ.new(@amqp)
@target = nil @target = nil
case @type case @mqtype
when "fanout" when "fanout"
@target = @mq.fanout(@name) @target = @mq.fanout(@name)
when "queue" when "queue"
@target = @mq.queue(@name, :durable => @urlopts["durable"] ? true : false) @target = @mq.queue(@name, :durable => @urlopts["durable"] ? true : false)
when "topic" when "topic"
@target = @mq.topic(@name) @target = @mq.topic(@name)
end # case @type end # case @mqtype
end # def register end # def register
def receive(event) def receive(event)