Module: AMQP

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

Overview

:stopdoc: this file was autogenerated on 2014-02-19 18:35:45 -0500 using amqp-0.8.json (mtime: 2013-11-07 17:14:52 -0500)

DO NOT EDIT! (edit protocol/codegen.rb instead, and run ‘rake spec: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'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.closingObject (readonly) Also known as: closing?

Returns the value of attribute closing.



12
13
14
# File 'lib/right_amqp/amqp.rb', line 12

def closing
  @closing
end

.connObject (readonly) Also known as: connection

Returns the value of attribute conn.



12
13
14
# File 'lib/right_amqp/amqp.rb', line 12

def conn
  @conn
end

.loggingObject

Returns the value of attribute logging.



11
12
13
# File 'lib/right_amqp/amqp.rb', line 11

def logging
  @logging
end

Class Method Details

.clientObject



66
67
68
# File 'lib/right_amqp/amqp/client.rb', line 66

def self.client
  @client ||= BasicClient
end

.client=(mod) ⇒ Object



70
71
72
73
# File 'lib/right_amqp/amqp/client.rb', line 70

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

.connect(*args) ⇒ Object



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

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

.connected?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/right_amqp/amqp.rb', line 116

def self.connected?
  !!@conn
end

.fork(workers) ⇒ Object



106
107
108
109
110
111
112
113
114
# File 'lib/right_amqp/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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/right_amqp/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) ⇒ 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.



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/right_amqp/amqp.rb', line 78

def self.start *args, &blk
  begin
    EM.run{
      @conn ||= connect *args
      @conn.callback(&blk) if blk
      @conn
    }
  rescue Exception => e
    @conn = nil
    raise e
  end
end

.stopObject



95
96
97
98
99
100
101
102
103
104
# File 'lib/right_amqp/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