lib/amqp/client.rb in celldee-bunny-0.0.4 vs lib/amqp/client.rb in celldee-bunny-0.0.5
- old
+ new
@@ -57,17 +57,17 @@
def close
send_frame(
Protocol::Channel::Close.new(:reply_code => 200, :reply_text => 'bye', :method_id => 0, :class_id => 0)
)
- puts "Error closing channel #{channel}" unless next_method.is_a?(Protocol::Channel::CloseOk)
+ raise ProtocolError, "Error closing channel #{channel}" unless next_method.is_a?(Protocol::Channel::CloseOk)
self.channel = 0
send_frame(
Protocol::Connection::Close.new(:reply_code => 200, :reply_text => 'Goodbye', :class_id => 0, :method_id => 0)
)
- puts "Error closing connection" unless next_method.is_a?(Protocol::Connection::CloseOk)
+ raise ProtocolError, "Error closing connection" unless next_method.is_a?(Protocol::Connection::CloseOk)
close_socket
end
def read(*args)
@@ -80,22 +80,25 @@
def start_session
@channel = 0
write(HEADER)
write([1, 1, VERSION_MAJOR, VERSION_MINOR].pack('C4'))
- raise ProtocolError, 'bad start connection' unless next_method.is_a?(Protocol::Connection::Start)
+ raise ProtocolError, 'Connection initiation failed' unless next_method.is_a?(Protocol::Connection::Start)
send_frame(
Protocol::Connection::StartOk.new(
{:platform => 'Ruby', :product => 'Bunny', :information => 'http://github.com/celldee/bunny', :version => VERSION},
'AMQPLAIN',
{:LOGIN => @user, :PASSWORD => @pass},
'en_US'
)
)
+
+ method = next_method
+ raise ProtocolError, "Connection failed - user: #{@user}, pass: #{@pass}" if method.nil?
- if next_method.is_a?(Protocol::Connection::Tune)
+ if method.is_a?(Protocol::Connection::Tune)
send_frame(
Protocol::Connection::TuneOk.new( :channel_max => 0, :frame_max => 131072, :heartbeat => 0)
)
end
@@ -112,9 +115,12 @@
Protocol::Access::Request.new(:realm => '/data', :read => true, :write => true, :active => true, :passive => true)
)
method = next_method
raise ProtocolError, 'Access denied' unless method.is_a?(Protocol::Access::RequestOk)
self.ticket = method.ticket
+
+ # return status
+ status
end
private
def buffer
\ No newline at end of file