Starts
EventMachine event loop unless it is already running and connects
to AMQP broker
using {AMQP.connect}
.
It is generally a good idea
to start EventMachine event loop in a separate thread and use {AMQP.connect} (for Web applications that do not use Thin or Goliath, it is the only option).
See {AMQP.connect} for information about arguments this method takes and
information about relevant topics such as authentication failure handling.
example
- Using AMQP.start to connect to AMQP broker, EventMachine loop isn't yet running
AMQP.start do |connection|
# default is to connect to localhost:5672, to root ("/") vhost as guest/guest
# this block never exits unless either `AMQP.stop` or `EM.stop` is called.
AMQP::Channel(connection) do |channel|
channel.queue("", :auto_delete => true).bind(channel.fanout("amq.fanout")).subscribe do |headers, payload|
# handle deliveries here
end
end
end
source code
def self.start(connection_options_or_string = {}, other_options = {}, &block)
EM.run do
if !@connection || @connection.closed? || @connection.closing?
@connection = connect(connection_options_or_string, other_options, &block)
end
@channel = Channel.new(@connection)
@connection
end
end