def initialize(channel, type, name, opts = {}, &block)
@channel = channel
@type = type
@opts = self.class.add_default_options(type, name, opts, block)
@default_routing_key = opts[:routing_key] || opts[:key] || AMQ::Protocol::EMPTY_STRING
@name = name unless name.empty?
@status = :unknown
@default_publish_options = (opts.delete(:default_publish_options) || {
:routing_key => @default_routing_key,
:mandatory => false,
:immediate => false
}).freeze
@default_headers = (opts.delete(:default_headers) || {
:content_type => DEFAULT_CONTENT_TYPE,
:persistent => false,
:priority => 0
}).freeze
super(channel.connection, channel, name, type)
unless name == "amq.#{type}" or name.empty? or opts[:no_declare]
@status = :opening
unless @opts[:no_declare]
@channel.once_open do
if block
shim = Proc.new do |exchange, declare_ok|
case block.arity
when 1 then block.call(exchange)
else
block.call(exchange, declare_ok)
end
end
self.declare(passive = @opts[:passive], durable = @opts[:durable], auto_delete = @opts[:auto_delete], nowait = @opts[:nowait], @opts[:arguments], &shim)
else
self.declare(passive = @opts[:passive], durable = @opts[:durable], auto_delete = @opts[:auto_delete], nowait = @opts[:nowait], @opts[:arguments])
end
end
end
else
@status = :opened
block.call(self) if block
end
@on_declare = block
end