Namespace

AMQP

Constants

VERSION

Attributes

closing[R]
closing?[R]
conn[R]
connection[R]
logging[RW]

Public Class Methods

client() click to toggle source
# File lib/amqp/client.rb, line 49
def self.client
  @client ||= BasicClient
end
client=(mod) click to toggle source
# File lib/amqp/client.rb, line 53
def self.client= mod
  mod.__send__ :include, AMQP
  @client = mod
end
connect(*args) click to toggle source
# File lib/amqp.rb, line 17
def self.connect *args
  Client.connect *args
end
fork(workers) click to toggle source
# File lib/amqp.rb, line 101
def self.fork workers
  EM.fork(workers) do
    # clean up globals in the fork
    Thread.current[:mq] = nil
    AMQP.instance_variable_set('@conn', nil)

    yield
  end
end
run(*args, &blk) click to toggle source
Alias for: start
settings() click to toggle source
# File lib/amqp.rb, line 21
def self.settings
  @settings ||= {
    # server address
    :host => '127.0.0.1',
    :port => PORT,

    # login details
    :user => 'guest',
    :pass => 'guest',
    :vhost => '/',

    # connection timeout
    :timeout => nil,

    # logging
    :logging => false,

    # ssl
    :ssl => false
  }
end
start(*args, &blk) click to toggle source

Must be called to startup the connection to the AMQP server.

The method takes several arguments and an optional block.

This takes any option that is also accepted by EventMachine::connect. Additionally, there are several AMQP-specific options.

  • :user => String (default 'guest')

The username as defined by the AMQP server.

  • :pass => String (default 'guest')

The password for the associated :user as defined by the AMQP server.

  • :vhost => String (default '/')

The virtual host as defined by the AMQP server.

  • :timeout => Numeric (default nil)

Measured in seconds.

  • :logging => true | false (default false)

Toggle the extremely verbose logging of all protocol communications between the client and the server. Extremely useful for debugging.

AMQP.start do
  # default is to connect to localhost:5672

  # define queues, exchanges and bindings here.
  # also define all subscriptions and/or publishers
  # here.

  # this block never exits unless EM.stop_event_loop
  # is called.
end

Most code will use the MQ api. Any calls to MQ.direct / MQ.fanout / MQ.topic / MQ.queue will implicitly call start. In those cases, it is sufficient to put your code inside of an EventMachine.run block. See the code examples in MQ for details.

# File lib/amqp.rb, line 78
def self.start *args, &blk
  EM.run{
    @conn ||= connect *args
    @conn.callback(&blk) if blk
    @conn
  }
end
Also aliased as: run
stop() click to toggle source
# File lib/amqp.rb, line 90
def self.stop
  if @conn and not @closing
    @closing = true
    @conn.close{
      yield if block_given?
      @conn = nil
      @closing = false
    }
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.