# File lib/bunny/exchange08.rb, line 36
    def initialize(client, name, opts = {})
      # check connection to server
      raise Bunny::ConnectionError, 'Not connected to server' if client.status == :not_connected
    
      @client, @name, @opts = client, name, opts
  
      # set up the exchange type catering for default names
      if name.match(/^amq\./)
        new_type = name.sub(/amq\./, '')
        # handle 'amq.match' default
        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
      
      # ignore the :nowait option if passed, otherwise program will hang waiting for a
      # response that will not be sent by the server
      opts.delete(:nowait)
      
      unless name == "amq.#{type}" or name == ''
        client.send_frame(
          Qrack::Protocol::Exchange::Declare.new(
            { :exchange => name, :type => type, :nowait => false }.merge(opts)
          )
        )

                                method = client.next_method

                                client.check_response(method, Qrack::Protocol::Exchange::DeclareOk,
                                    "Error declaring exchange #{name}: type = #{type}")

      end
    end