Module: AMQP::BasicClient

Defined in:
lib/amqp/client.rb

Instance Method Summary collapse

Instance Method Details

#process_frame(frame) ⇒ Object



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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/amqp/client.rb', line 7

def process_frame frame
  if mq = channels[frame.channel]
    mq.process_frame(frame)
    return
  end

  case frame
  when Frame::Method
    case method = frame.payload
    when Protocol::Connection::Start
      send Protocol::Connection::StartOk.new({:platform => 'Ruby/EventMachine',
                                              :product => 'AMQP',
                                              :information => 'http://github.com/tmm1/amqp',
                                              :version => VERSION},
                                             'AMQPLAIN',
                                             {:LOGIN => @settings[:user],
                                              :PASSWORD => @settings[:pass]},
                                             'en_US')

    when Protocol::Connection::Tune
      send Protocol::Connection::TuneOk.new(:channel_max => 0,
                                            :frame_max => 131072,
                                            :heartbeat => 0)

      send Protocol::Connection::Open.new(:virtual_host => @settings[:vhost],
                                          :capabilities => '',
                                          :insist => @settings[:insist])

    when Protocol::Connection::OpenOk
      succeed(self)

    when Protocol::Connection::Redirect
      (redir_host, redir_port) = method.host.split(":")
      redir_port = redir_port.to_i #important!
      STDERR.puts "Redirecting to #{redir_host}:#{redir_port}"
      old_on_disconnect = @on_disconnect
      @on_disconnect = Proc.new do
        @on_disconnect = old_on_disconnect
        reconnect true, redir_host, redir_port
      end
      
    when Protocol::Connection::Close
      # raise Error, "#{method.reply_text} in #{Protocol.classes[method.class_id].methods[method.method_id]}"
      STDERR.puts "#{method.reply_text} in #{Protocol.classes[method.class_id].methods[method.method_id]}"

    when Protocol::Connection::CloseOk
      @on_disconnect.call if @on_disconnect
    end
  end
end