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/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

VERSION =
'0.6.1'
DIR =
File.expand_path(File.dirname(File.expand_path(__FILE__)))
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,
]

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.closingObject (readonly) Also known as: closing?

Returns the value of attribute closing.



17
18
19
# File 'lib/amqp.rb', line 17

def closing
  @closing
end

.connObject (readonly) Also known as: connection

Returns the value of attribute conn.



17
18
19
# File 'lib/amqp.rb', line 17

def conn
  @conn
end

.loggingObject

Returns the value of attribute logging.



16
17
18
# File 'lib/amqp.rb', line 16

def logging
  @logging
end

Class Method Details

.clientObject



49
50
51
# File 'lib/amqp/client.rb', line 49

def self.client
  @client ||= BasicClient
end

.client=(mod) ⇒ Object



53
54
55
56
# File 'lib/amqp/client.rb', line 53

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

.connect(*args) ⇒ Object



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

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

.fork(workers) ⇒ Object



106
107
108
109
110
111
112
113
114
# File 'lib/amqp.rb', line 106

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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/amqp.rb', line 26

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.



83
84
85
86
87
88
89
# File 'lib/amqp.rb', line 83

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

.stopObject



95
96
97
98
99
100
101
102
103
104
# File 'lib/amqp.rb', line 95

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