LoginSignup
1
1

More than 5 years have passed since last update.

AMQP.start

Posted at

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
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1