Class: Bunny::Client

Inherits:
Qrack::Client show all
Defined in:
lib/bunny-ext/bunny/client08.rb,
lib/bunny-ext/bunny/client09.rb

Constant Summary

Constants inherited from Qrack::Client

Qrack::Client::SOCKET_TIMEOUT

Instance Method Summary collapse

Methods inherited from Qrack::Client

#initialize_with_timeout_opts, #send_command, #set_socket_timeouts, #socket

Instance Method Details

#next_frame(opts = {}) ⇒ Object

Overwritten with a version that uses Bunny::Timer::timeout instead of Object#timeout which is either timeout.rb (ruby 1.9.x) or SystemTimer (ruby 1.8.x) read: ph7spot.com/musings/system-timer

Raises:

  • (Bunny::ConnectionError)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bunny-ext/bunny/client08.rb', line 7

def next_frame(opts = {})
  frame = nil

  case
    when channel.frame_buffer.size > 0
      frame = channel.frame_buffer.shift
    when opts.has_key?(:timeout)
      Bunny::Timer::timeout(opts[:timeout], Qrack::ClientTimeout) do
        frame = Qrack::Transport::Frame.parse(buffer)
      end
    else
      frame = Qrack::Transport::Frame.parse(buffer)
  end

  @logger.info("received") { frame } if @logging
    
  raise Bunny::ConnectionError, 'No connection to server' if (frame.nil? and !connecting?)

  # Monitor server activity and discard heartbeats
  @message_in = true

  case
    when frame.is_a?(Qrack::Transport::Heartbeat)
      next_frame(opts)
    when frame.nil?
      frame
    when ((frame.channel != channel.number) and (frame.channel != 0))
      channel.frame_buffer << frame
      next_frame(opts)
    else
      frame
  end

end