Module: AMQP

Included in:
MQ, MQ::Exchange, MQ::Header, MQ::Queue
Defined in:
lib/amqp/spec.rb,
lib/amqp.rb,
lib/amqp/spec.rb,
lib/amqp/frame.rb,
lib/amqp/buffer.rb,
lib/amqp/client.rb,
lib/amqp/server.rb,
lib/amqp/version.rb,
lib/amqp/protocol.rb

Overview

:stopdoc: this file was autogenerated on Thu Jul 09 15:17:33 -0700 2009 using amqp-0.8.json (mtime: Sat Jan 03 08:58:13 -0600 2009)

DO NOT EDIT! (edit protocol/codegen.rb instead, and run ‘rake codegen`)

Defined Under Namespace

Modules: BasicClient, Client, Protocol, Server Classes: Buffer, Error, Frame

Constant Summary collapse

HEADER =
"AMQP".freeze
VERSION_MAJOR =
8
VERSION_MINOR =
0
PORT =
5672
RESPONSES =
{
  200 => :REPLY_SUCCESS,
  310 => :NOT_DELIVERED,
  311 => :CONTENT_TOO_LARGE,
  312 => :NO_ROUTE,
  313 => :NO_CONSUMERS,
  403 => :ACCESS_REFUSED,
  404 => :NOT_FOUND,
  405 => :RESOURCE_LOCKED,
  406 => :PRECONDITION_FAILED,
  320 => :CONNECTION_FORCED,
  402 => :INVALID_PATH,
}
FIELDS =
[
  :bit,
  :long,
  :longlong,
  :longstr,
  :octet,
  :short,
  :shortstr,
  :table,
  :timestamp,
]
VERSION =
'0.6.7.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.closingObject (readonly) Also known as: closing?

Returns the value of attribute closing.



23
24
25
# File 'lib/amqp.rb', line 23

def closing
  @closing
end

.connObject (readonly) Also known as: connection

Returns the value of attribute conn.



23
24
25
# File 'lib/amqp.rb', line 23

def conn
  @conn
end

.loggingObject

Returns the value of attribute logging.



22
23
24
# File 'lib/amqp.rb', line 22

def logging
  @logging
end

Class Method Details

.clientObject



59
60
61
# File 'lib/amqp/client.rb', line 59

def self.client
  @client ||= BasicClient
end

.client=(mod) ⇒ Object



63
64
65
66
# File 'lib/amqp/client.rb', line 63

def self.client= mod
  mod.__send__ :include, AMQP
  @client = mod
end

.connect(*args) ⇒ Object



28
29
30
# File 'lib/amqp.rb', line 28

def self.connect *args
  Client.connect *args
end

.fork(workers) ⇒ Object



112
113
114
115
116
117
118
119
120
# File 'lib/amqp.rb', line 112

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

.settingsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/amqp.rb', line 32

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) ⇒ Object Also known as: run

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.



89
90
91
92
93
94
95
# File 'lib/amqp.rb', line 89

def self.start *args, &blk
  EM.run {
    @conn ||= connect *args
    @conn.callback(&blk) if blk
    @conn
  }
end

.stopObject



101
102
103
104
105
106
107
108
109
110
# File 'lib/amqp.rb', line 101

def self.stop
  if @conn and not @closing
    @closing = true
    @conn.close {
      yield if block_given?
      @conn = nil
      @closing = false
    }
  end
end