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.match(/^amq\./)
new_type = name.sub(/amq\./, '')
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 name == "amq.#{type}" or name == ''
client.send_frame(
Qrack::Protocol09::Exchange::Declare.new(
{ :exchange => name, :type => type, :nowait => false,
:reserved_1 => 0, :reserved_2 => false, :reserved_3 => false }.merge(opts)
)
)
method = client.next_method
client.check_response(method, Qrack::Protocol09::Exchange::DeclareOk,
"Error declaring exchange #{name}: type = #{type}")
end
end