def initialize(client, name, opts = {})
raise Bunny::ConnectionError, 'Not connected to server' if client.status == :not_connected
@client, @name, @opts = client, name, opts
if name =~ /^amq\.(.+)$/
predeclared = true
new_type = $1
new_type = 'headers' if new_type == 'match'
@type = new_type.to_sym
else
@type = opts[:type] || :direct
end
@key = opts[:key]
@client.exchanges[@name] ||= self
opts.delete(:nowait)
unless predeclared or name == ''
opts = { :exchange => name, :type => type, :nowait => false }.merge(opts)
client.send_frame(Qrack::Protocol::Exchange::Declare.new(opts))
method = client.next_method
client.check_response(method, Qrack::Protocol::Exchange::DeclareOk, "Error declaring exchange #{name}: type = #{type}")
end
end