Module: ZMQP
- Defined in:
- lib/zmqp/spec.rb,
lib/zmqp.rb,
lib/zmqp.rb,
lib/version.rb
Overview
This file contains all specifications and conventions that allow ZMQP to impersonate AMQP
Constant Summary collapse
- VERSION_FILE =
:nodoc:
Pathname.new(__FILE__).dirname + '../VERSION'
- VERSION =
VERSION_FILE.exist? ? VERSION_FILE.read.strip : nil
- PORT =
PORT to be used by lightweight ZMQP broker (more like service registry, in fact)
5673
Class Attribute Summary collapse
-
.closing ⇒ Object
(also: closing?)
readonly
Returns the value of attribute closing.
-
.conn ⇒ Object
(also: connection)
readonly
Returns the value of attribute conn.
-
.logging ⇒ Object
Returns the value of attribute logging.
Class Method Summary collapse
- .connect(*args) ⇒ Object
-
.require_libs(libs, opts = {}) ⇒ Object
Requires ruby source file(s).
- .settings ⇒ Object
-
.start(*args, &blk) ⇒ Object
(also: run)
Must be called to startup the connection to lightweight service broker (was:the AMQP server).
- .stop ⇒ Object
Class Attribute Details
.closing ⇒ Object (readonly) Also known as: closing?
Returns the value of attribute closing.
37 38 39 |
# File 'lib/zmqp.rb', line 37 def closing @closing end |
.conn ⇒ Object (readonly) Also known as: connection
Returns the value of attribute conn.
37 38 39 |
# File 'lib/zmqp.rb', line 37 def conn @conn end |
.logging ⇒ Object
Returns the value of attribute logging.
36 37 38 |
# File 'lib/zmqp.rb', line 36 def logging @logging end |
Class Method Details
.connect(*args) ⇒ Object
42 43 44 |
# File 'lib/zmqp.rb', line 42 def self.connect *args Client.connect *args end |
.require_libs(libs, opts = {}) ⇒ Object
Requires ruby source file(s). Accepts either single filename/glob or Array of filenames/globs. Accepts following options:
- :file
-
Lib(s) required relative to this file - defaults to __FILE__
- :dir
-
Required lib(s) located under this dir name - defaults to gem name
13 14 15 16 17 18 19 |
# File 'lib/zmqp.rb', line 13 def self.require_libs( libs, opts={} ) file = Pathname.new(opts[:file] || __FILE__) [libs].flatten.each do |lib| name = file.dirname + (opts[:dir] || file.basename('.*')) + lib.gsub(/(?<!.rb)$/, '.rb') Pathname.glob(name.to_s).sort.each {|rb| require rb} end end |
.settings ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/zmqp.rb', line 46 def self.settings @settings ||= { # broker 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 lightweight service broker (was:the AMQP server).
The method takes several arguments and an optional block.
This takes any option that is also accepted by *??* ZMQMachine::connect. Additionally, there are several ZMQP-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.
103 104 105 106 107 108 109 |
# File 'lib/zmqp.rb', line 103 def self.start *args, &blk EM.run{ @conn ||= connect *args @conn.callback(&blk) if blk @conn } end |
.stop ⇒ Object
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/zmqp.rb', line 115 def self.stop if @conn and not @closing @closing = true @conn.close{ yield if block_given? @conn = nil @closing = false } end end |