def open_connection
send_frame(
Qrack::Protocol09::Connection::StartOk.new(
:client_properties => {:platform => 'Ruby', :product => 'Bunny', :information => 'http://github.com/celldee/bunny', :version => VERSION},
:mechanism => 'PLAIN',
:response => "\0" + @user + "\0" + @pass,
:locale => 'en_US'
)
)
frame = next_frame
raise Bunny::ProtocolError, "Connection failed - user: #{@user}" if frame.nil?
method = frame.payload
if method.is_a?(Qrack::Protocol09::Connection::Tune)
send_frame(
Qrack::Protocol09::Connection::TuneOk.new( :channel_max => @channel_max, :frame_max => @frame_max, :heartbeat => @heartbeat)
)
end
send_frame(
Qrack::Protocol09::Connection::Open.new(:virtual_host => @vhost, :reserved_1 => 0, :reserved_2 => false)
)
raise Bunny::ProtocolError, 'Cannot open connection' unless next_method.is_a?(Qrack::Protocol09::Connection::OpenOk)
end