# File lib/bunny/exchange09.rb, line 31
    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 =~ /^amq\.(.+)$/
        predeclared = true
        new_type = $1
        # 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 predeclared or name == ''
        opts = {
          :exchange => name, :type => type, :nowait => false,
          :deprecated_ticket => 0, :deprecated_auto_delete => false, :deprecated_internal => false
        }.merge(opts)

        client.send_frame(Qrack::Protocol09::Exchange::Declare.new(opts))

        method = client.next_method

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