Module | AMQP

In:

lib/amqp/consumer.rb
lib/amqp/session.rb
lib/amqp/connection.rb
lib/amqp/header.rb
lib/amqp/broker.rb
lib/amqp/integration/rails.rb
lib/amqp/version.rb
lib/amqp/channel.rb
lib/amqp/utilities/event_loop_helper.rb
lib/amqp/utilities/server_type.rb
lib/amqp/exceptions.rb
lib/amqp/deprecated/fork.rb
lib/amqp/deprecated/logger.rb
lib/amqp/deprecated/rpc.rb
lib/amqp/int_allocator.rb
lib/amqp/client.rb
lib/amqp/bit_set.rb
lib/amqp/exchange.rb
lib/amqp/queue.rb

encoding: utf-8

### Methods

channel channel= client client= closing? conn conn= connect connection connection= fork logging logging= run settings start stop

### Classes and Modules

Module AMQP::Client
Module AMQP::Integration
Module AMQP::Utilities
Class AMQP::BitSet
Class AMQP::BlankSlate
Class AMQP::Broker
Class AMQP::Channel
Class AMQP::ChannelClosedError
Class AMQP::Consumer
Class AMQP::Error
Class AMQP::Exchange
Class AMQP::Header
Class AMQP::IncompatibleOptionsError
Class AMQP::IntAllocator
Class AMQP::Logger
Class AMQP::PossibleAuthenticationFailureError
Class AMQP::Queue
Class AMQP::RPC
Class AMQP::Session
Class AMQP::TCPConnectionFailed

### Constants

VERSION | = | '0.9.7' |  | amqp gem version. Not to be confused with the AMQP protocol version it implements. For that, see {AMQ::Protocol::VERSION} @see AMQ::Protocol::VERSION @return [String] AMQP gem version

### Public Class methods

channel()

"Default channel". A placeholder for apps that only want to use one channel. This channel is not global, not used under the hood by methods like {AMQP::Exchange#initialize} and only shared by exchanges/queues you decide on. To reiterate: this is only a conventience accessor, since many apps (especially Web apps) can get by with just one connection and one channel.

@api public

channel=(value)

A placeholder for applications that only need one channel. If you use {AMQP.start} to set up default connection, {AMQP.channel} is open on that connection, but can be replaced by your application.

@see AMQP.channel @api public

client()

@private

client=(value)

@private

closing?()

Indicates that default connection is closing.

@return [Boolean] @api public

conn()

Alias for {AMQP.connection} @deprecated @api public

conn=(value)

Alias for {AMQP.connection=} @deprecated @api public

connect(connection_options_or_string = {}, other_options = {}, &block)

Connects to AMQP broker and yields connection object to the block as soon as connection is considered open.

@example Using AMQP.connect with default connection settings

      AMQP.connect do |connection|
        AMQP::Channel.new(connection) do |channel|
          # channel is ready: set up your messaging flow by creating exchanges,
          # queues, binding them together and so on.
        end
      end

@example Using AMQP.connect to connect to a public RabbitMQ instance with connection settings given as a hash

      AMQP.connect(:host => "dev.rabbitmq.com", :username => "guest", :password => "guest") do |connection|
        AMQP::Channel.new(connection) do |channel|
          # ...
        end
      end

@example Using AMQP.connect to connect to a public RabbitMQ instance with connection settings given as a URI

      AMQP.connect "amqp://guest:guest@dev.rabbitmq.com:5672", :on_possible_authentication_failure => Proc.new { puts("Looks like authentication has failed") } do |connection|
        AMQP::Channel.new(connection) do |channel|
          # ...
        end
      end

@overload connect(connection_string, options = {})

      Used to pass connection parameters as a connection string
      @param [String] :connection_string AMQP connection URI, à la JDBC connection string. For example: amqp://bus.megacorp.internal:5877/qa

@overload connect(connection_options)

      Used to pass connection options as a Hash.
      @param [Hash] :connection_options AMQP connection options (:host, :port, :username, :vhost, :password)

@option connection_options_or_string [String] :host ("localhost") Host to connect to. @option connection_options_or_string [Integer] :port (5672) Port to connect to. @option connection_options_or_string [String] :vhost ("/") Virtual host to connect to. @option connection_options_or_string [String] :username ("guest") Username to use. Also can be specified as :user. @option connection_options_or_string [String] :password ("guest") Password to use. Also can be specified as :pass. @option connection_options_or_string [Hash] :ssl TLS (SSL) parameters to use. @option connection_options_or_string [call] :on_tcp_connection_failure A callable object that will be run if connection to server fails @option connection_options_or_string [call] :on_possible_authentication_failure A callable object that will be run if authentication fails (see Authentication failure section)

h2. Handling authentication failures

AMQP 0.9.1 specification dictates that broker closes TCP connection when it detects that authentication has failed. However, broker does exactly the same thing when other connection-level exception occurs so there is no way to guarantee that connection was closed because of authentication failure.

Because of that, AMQP gem follows Java client example and hints at possibility of authentication failure. To handle it, pass a callable object (a proc, a lambda, an instance of a class that responds to call) with :on_possible_authentication_failure option.

@note This method assumes that EventMachine even loop is already running. If it is not the case or you are not sure, we recommend you use {AMQP.start} instead.

          It takes exactly the same parameters.

@return [AMQP::Session] @api public

connection()

Default connection. When you do not pass connection instance to methods like {Channel#initialize}, AMQP gem will use this default connection.

@api public

connection=(value)

Sets global connection object. @api public

fork(workers) {|| ...}

@deprecated @private

logging()

@return [Boolean] Current global logging value @api public

logging=(value)

@return [Boolean] Sets current global logging value @api public

run(*args, &block)

Alias for {AMQP.start} @api public

settings()

@return [Hash] Default AMQP connection settings. This hash may be modified. @api public

start(connection_options_or_string = {}, other_options = {}, &block)

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

@api public

stop(reply_code = 200, reply_text = "Goodbye", &block)

Properly closes default AMQP connection and then underlying TCP connection. Pass it a block if you want a piece of code to be run once default connection is successfully closed.

@note If default connection was never estabilished or is in the closing state already,

          this method has no effect.

@api public

[Validate]