Skip to content

Instantly share code, notes, and snippets.

@prepor
Created May 24, 2010 15:04
Show Gist options
  • Save prepor/411973 to your computer and use it in GitHub Desktop.
Save prepor/411973 to your computer and use it in GitHub Desktop.
amqp client with redirect.
# Support of amqp redirect method. It uses in amqp-clusters.
# For use: AMQP.client = AmqpClient
module AmqpClient
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
host, port = method.host.split(':')
@settings[:host], @settings[:port] = host, port.to_i
reconnect
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
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment