Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'release/0.1.0'

  • Loading branch information...
commit 74c524b49c37c7b7a4f5bac28023e30dd5510ee8 2 parents 8b0a679 + d58d1ec
@FGRibreau authored
View
8 .gitignore
@@ -0,0 +1,8 @@
+# node
+node_modules
+
+*.rdb
+*.log
+
+# mac
+DS_STORE
View
4 .travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+ - 0.4
+ - 0.6
View
21 Cakefile
@@ -0,0 +1,21 @@
+{spawn, exec} = require 'child_process'
+
+task 'build', 'continually build the amqp-dsl library with --watch', ->
+ coffee = spawn 'coffee', ['-cw', '-o', 'lib', 'src']
+ coffee.stdout.on 'data', (data) -> console.log data.toString().trim()
+
+task 'install', 'install dependencies', ->
+ npm = spawn 'npm', ['install']
+ npm.stdout.on 'data', (data) -> console.log data.toString().trim()
+
+task 'doc', 'rebuild the documentation', ->
+ exec([
+ 'rm -r docs'
+ './node_modules/docco/bin/docco src/*.coffee examples/*.coffee'
+ ].join(' && '), (err) ->
+ throw err if err
+ )
+
+task 'test', 'run tests', ->
+ npm = spawn 'npm', ['test']
+ npm.stdout.on 'data', (data) -> console.log data.toString().trim()
View
27 LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) 2011, Francois-Guillaume Ribreau <node@fgribreau.com>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ * Neither the name of amqp-dsl nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
122 README.md
@@ -0,0 +1,122 @@
+## Fluent Interface for dealing with AMQP on NodeJS [![Build Status](https://secure.travis-ci.org/FGRibreau/node-amqp-dsl.png)](http://travis-ci.org/FGRibreau/node-amqp-dsl) ##
+
+AMQP-DSL is a [fluent interface](http://en.wikipedia.org/wiki/Fluent_interface) wrapper for [node-amqp](https://github.com/postwait/node-amqp) and help you write AMQP binding code in a clean and efficient way.
+
+## Installation
+
+ $ npm install amqp-dsl
+
+## Usage overview
+
+### Simple connection (more details: `docs/example-connection`)
+
+```coffeescript
+
+amqp = require 'amqp-dsl'
+
+amqp.login(
+
+ login: 'user'
+ password: 'password'
+ host: 'localhost'
+
+).connect((err, amqp) ->
+
+ if err
+ throw err
+ return
+
+ console.log 'We are connected !'
+
+)
+```
+
+### Simple example (more details: `docs/example-simple`)
+
+```coffeescript
+
+AmqpDsl = require 'amqp-dsl'
+
+AmqpDsl.login(
+ login: 'legen'
+ password: 'dary'
+)
+.on( 'close', () -> console.error "RabbitMQ connection closed" )
+.on( 'error', (err) -> console.error "RabbitMQ error", err )
+.on( 'ready', () -> console.log "Connected to RabbitMQ" )
+
+.queue( 'testQueue', (queue) -> console.log "Connected to Queue", queue.name )
+ .bind( 'stream', '#' )
+ .subscribe( (message, header, deliveryInfo) -> )
+
+.queue( 'queue2' )
+ .bind( 'search', '#.ok' )
+
+.queue( 'queue3', passive:true )
+
+.connect( (err, amqp) ->
+
+ if err
+ throw err
+ return
+
+ # Do other stuff with `amqp` like subscribing to a queue
+
+ queue3 = amqp.queues.queue3
+
+ queue3.subscribe( ack:true, ( message, header, deliveryInfo ) ->
+ console.log "Hey ! We got one new message !"
+ queue3.shift()
+ )
+
+)
+```
+
+See `examples/` and `docs/` for more information.
+
+## API
+
+### .login
+ * `login( options = {} )`
+
+### .on
+ * `on( event, listener )`
+
+### .exchange
+ * `.exchange( name, options )`
+ * `.exchange( name, callback(exchange) )`
+ * `.exchange( name, options, callback(exchange) )`
+
+### .queue
+ * `.queue( name, options )`
+ * `.queue( name, callback(queue) )`
+ * `.queue( name, options, callback(queue) )`
+
+### .queue(...).subscribe
+ * `.subscribe( callback(message, header, deliveryInfo) )`
+ * `.subscribe( options, callback(message, header, deliveryInfo) )`
+
+### .queue(...).bind
+ * `.bind( name, routingKey )`
+
+### .connect
+ * `.connect( amqp, callback(err, amqp) )`
+ * `.connect( callback(err, amqp) )`
+
+The `amqp` argument is simply hashtable with the following properties:
+
+ * queues (hashtable of `AMQP::queues`)
+ * exchanges (hashtable of `AMQP::Exchange`)
+ * connection (`AMQP::Connection`)
+
+
+## Documentation
+
+### Build documentation
+ $ cake doc
+
+... and browse `docs/`
+
+## Test
+
+ $ npm test
View
176 docs/AmqpDsl.html
@@ -0,0 +1,176 @@
+<!DOCTYPE html> <html> <head> <title>AmqpDsl.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="example-advanced.html"> example-advanced.coffee </a> <a class="source" href="example-connection.html"> example-connection.coffee </a> <a class="source" href="example-simple.html"> example-simple.coffee </a> <a class="source" href="AmqpDsl.html"> AmqpDsl.coffee </a> <a class="source" href="AmqpExchange.html"> AmqpExchange.coffee </a> <a class="source" href="AmqpQueue.html"> AmqpQueue.coffee </a> <a class="source" href="IndexedList.html"> IndexedList.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> AmqpDsl.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Amqp-DSL - Fluent interface for node-amqp</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">async = </span><span class="nx">require</span> <span class="s1">&#39;async&#39;</span>
+
+<span class="nv">IndexedList = </span><span class="nx">require</span> <span class="s1">&#39;./IndexedList&#39;</span>
+<span class="nv">AmqpQueue = </span><span class="nx">require</span> <span class="s1">&#39;./AmqpQueue&#39;</span>
+<span class="nv">AmqpExchange = </span><span class="nx">require</span> <span class="s1">&#39;./AmqpExchange&#39;</span>
+
+<span class="nv">module.exports = </span><span class="k">class</span> <span class="nx">AmqpDsl</span>
+
+ <span class="nx">LISTENNERS</span> <span class="o">=</span><span class="p">[</span><span class="s1">&#39;error&#39;</span><span class="p">,</span><span class="s1">&#39;close&#39;</span><span class="p">,</span><span class="s1">&#39;ready&#39;</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h1>Public API</h1>
+
+<h3>require('amqp-dsl').login</h3>
+
+<ul>
+<li><code>login( options = {} )</code></li>
+</ul> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">AmqpDsl.login = </span><span class="nf">(opt = {}) -&gt;</span>
+ <span class="k">new</span> <span class="nx">AmqpDsl</span><span class="p">(</span><span class="nx">opt</span><span class="p">)</span>
+
+ <span class="nx">constructor</span><span class="o">:</span><span class="nf">(opt = {}) -&gt;</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Defaults</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@_login = </span><span class="s1">&#39;&#39;</span>
+ <span class="vi">@_password = </span><span class="s1">&#39;&#39;</span>
+ <span class="vi">@_host = </span><span class="s1">&#39;&#39;</span>
+ <span class="vi">@_port = </span><span class="mi">5672</span>
+ <span class="vi">@_vhost = </span><span class="s1">&#39;/&#39;</span>
+
+ <span class="vi">@_conn = </span><span class="kc">null</span>
+ <span class="vi">@_callback = </span><span class="o">-&gt;</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Constructor arguments</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">opt</span><span class="p">.</span><span class="nx">login</span> <span class="o">and</span> <span class="p">(</span><span class="vi">@_login = </span><span class="nx">opt</span><span class="p">.</span><span class="nx">login</span><span class="p">)</span>
+ <span class="nx">opt</span><span class="p">.</span><span class="nx">password</span> <span class="o">and</span> <span class="p">(</span><span class="vi">@_password = </span><span class="nx">opt</span><span class="p">.</span><span class="nx">password</span><span class="p">)</span>
+ <span class="nx">opt</span><span class="p">.</span><span class="nx">host</span> <span class="o">and</span> <span class="p">(</span><span class="vi">@_host = </span><span class="nx">opt</span><span class="p">.</span><span class="nx">host</span><span class="p">)</span>
+ <span class="nx">opt</span><span class="p">.</span><span class="nx">port</span> <span class="o">and</span> <span class="p">(</span><span class="vi">@_port = </span><span class="nx">opt</span><span class="p">.</span><span class="nx">port</span><span class="p">)</span>
+ <span class="nx">opt</span><span class="p">.</span><span class="nx">vhost</span> <span class="o">and</span> <span class="p">(</span><span class="vi">@_vhost = </span><span class="nx">opt</span><span class="p">.</span><span class="nx">vhost</span><span class="p">)</span>
+ <span class="nx">opt</span><span class="p">.</span><span class="nx">login</span> <span class="o">and</span> <span class="p">(</span><span class="vi">@_login = </span><span class="nx">opt</span><span class="p">.</span><span class="nx">login</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Events</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@_events = </span><span class="p">{}</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Exchanges</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@_exchanges = </span><span class="k">new</span> <span class="nx">IndexedList</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Queues</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@_queues = </span><span class="k">new</span> <span class="nx">IndexedList</span><span class="p">()</span>
+ </pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <h3>.on</h3>
+
+<ul>
+<li><code>on( event, listener )</code></li>
+</ul> </td> <td class="code"> <div class="highlight"><pre> <span class="kc">on</span><span class="o">:</span><span class="nf">( event, listener ) -&gt;</span>
+ <span class="k">if</span> <span class="o">!~</span><span class="nx">LISTENNERS</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">event</span><span class="p">)</span>
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s2">&quot;Event &#39;#{event}&#39; is invalid&quot;</span><span class="p">)</span>
+
+ <span class="nx">@_events</span><span class="p">[</span><span class="nx">event</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">@_events</span><span class="p">[</span><span class="nx">event</span><span class="p">])</span>
+
+ <span class="nx">@_events</span><span class="p">[</span><span class="nx">event</span><span class="p">].</span><span class="nx">push</span><span class="p">(</span><span class="nx">listener</span><span class="p">)</span>
+
+ <span class="k">this</span>
+ </pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <h3>.exchange</h3>
+
+<ul>
+<li><code>.exchange( name, options )</code></li>
+<li><code>.exchange( name, callback(exchange) )</code></li>
+<li><code>.exchange( name, options, callback(exchange) )</code></li>
+</ul> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">exchange</span><span class="o">:</span><span class="nf">( name, options, openCallback ) -&gt;</span>
+ <span class="nx">@_exchanges</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="k">new</span> <span class="nx">AmqpExchange</span><span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">options</span><span class="p">,</span> <span class="nx">openCallback</span><span class="p">))</span>
+ <span class="k">this</span>
+ </pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <h3>.queue</h3>
+
+<ul>
+<li><code>.queue( name, options )</code></li>
+<li><code>.queue( name, callback(queue) )</code></li>
+<li><code>.queue( name, options, callback(queue) )</code></li>
+</ul> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">queue</span><span class="o">:</span><span class="nf">( name, options, openCallback ) -&gt;</span>
+ <span class="nx">@_queues</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="k">new</span> <span class="nx">AmqpQueue</span><span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">options</span><span class="p">,</span> <span class="nx">openCallback</span><span class="p">))</span>
+ <span class="k">this</span>
+ </pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <h3>.queue(...).subscribe</h3>
+
+<ul>
+<li><code>.subscribe( callback(message, header, deliveryInfo) )</code></li>
+<li><code>.subscribe( options, callback(message, header, deliveryInfo) )</code></li>
+</ul> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">subscribe</span><span class="o">:</span><span class="nf">( options, messageListener ) -&gt;</span>
+ <span class="nv">queue = </span><span class="nx">@_queues</span><span class="p">.</span><span class="nx">last</span><span class="p">()</span>
+
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s2">&quot;At least one queue must be declared&quot;</span><span class="p">)</span> <span class="k">if</span> <span class="o">!</span><span class="nx">queue</span>
+
+ <span class="nx">queue</span><span class="p">.</span><span class="nx">subscribe</span><span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="nx">messageListener</span><span class="p">)</span>
+ <span class="k">this</span>
+ </pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <h3>.queue(...).bind</h3>
+
+<ul>
+<li><code>.bind( name, routingKey )</code></li>
+</ul> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">bind</span><span class="o">:</span><span class="nf">( name, routingKey ) -&gt;</span>
+ <span class="nv">queue = </span><span class="nx">@_queues</span><span class="p">.</span><span class="nx">last</span><span class="p">()</span>
+
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s2">&quot;At least one queue must be declared&quot;</span><span class="p">)</span> <span class="k">if</span> <span class="o">!</span><span class="nx">queue</span>
+
+ <span class="nx">queue</span><span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">routingKey</span><span class="p">)</span>
+ <span class="k">this</span>
+ </pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <h3>.connect</h3>
+
+<ul>
+<li><code>.connect( amqp, callback(err, amqp) )</code></li>
+<li><code>.connect( callback(err, amqp) )</code></li>
+</ul>
+
+<p><code>amqp</code> parameter is an hashtable which contain</p>
+
+<pre><code> queues:
+ sampleQueue:[Amqp::Queue]
+
+ exchanges:
+ sampleExchange:[Amqp::Exchange]
+
+ connection: [Amqp::Connection]
+</code></pre> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">connect</span><span class="o">:</span><span class="nf">(amqp, @_callback)-&gt;</span>
+
+ <span class="k">if</span> <span class="k">typeof</span> <span class="nx">amqp</span> <span class="o">is</span> <span class="s2">&quot;function&quot;</span>
+ <span class="vi">@_callback = </span><span class="nx">amqp</span>
+ <span class="nv">amqp = </span><span class="nx">require</span> <span class="s1">&#39;amqp&#39;</span>
+
+ <span class="nx">@_connect</span><span class="p">(</span><span class="nx">amqp</span><span class="p">)</span>
+
+ <span class="kc">null</span>
+ </pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <h1>Private API</h1> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>Create the connection to amqp and bind events</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">_connect</span><span class="o">:</span><span class="nf">(amqp) -&gt;</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>Create connection</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@conn = </span><span class="nx">amqp</span><span class="p">.</span><span class="nx">createConnection</span><span class="p">({</span>
+ <span class="nv">host: </span><span class="nx">@_host</span><span class="p">,</span>
+ <span class="nv">port: </span><span class="nx">@_port</span><span class="p">,</span>
+ <span class="nv">login: </span><span class="nx">@_login</span><span class="p">,</span>
+ <span class="nv">password: </span><span class="nx">@_password</span><span class="p">,</span>
+ <span class="nv">vhost: </span><span class="nx">@_vhost</span>
+ <span class="p">})</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>When the connection will be ready, connect the exchanges</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">@on</span> <span class="s1">&#39;ready&#39;</span><span class="p">,</span> <span class="p">()</span> <span class="o">=&gt;</span> <span class="nx">@_connectExchanges</span><span class="p">(</span><span class="nx">@_connectQueues</span><span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="k">this</span><span class="p">))</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <p>Set event listeners</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">@conn</span><span class="p">.</span><span class="kc">on</span><span class="p">(</span><span class="nx">event</span><span class="p">,</span> <span class="nx">@_getListenerFor</span><span class="p">(</span><span class="nx">event</span><span class="p">))</span> <span class="k">for</span> <span class="nx">event</span> <span class="k">of</span> <span class="nx">@_events</span>
+ </pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>Return a listener fonction for the event <code>event</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_getListenerFor: </span><span class="nf">(event) -&gt;</span>
+
+ <span class="k">if</span> <span class="nx">@_events</span><span class="p">[</span><span class="nx">event</span><span class="p">].</span><span class="nx">length</span> <span class="o">==</span> <span class="mi">1</span>
+ <span class="k">return</span> <span class="nx">@_events</span><span class="p">[</span><span class="nx">event</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
+ <span class="k">else</span>
+ <span class="k">return</span> <span class="p">(</span><span class="nx">args</span><span class="p">...)</span> <span class="o">=&gt;</span>
+ <span class="nx">listener</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">args</span><span class="p">)</span> <span class="k">for</span> <span class="nx">listener</span> <span class="k">in</span> <span class="nx">@_events</span><span class="p">[</span><span class="nx">event</span><span class="p">]</span>
+ <span class="kc">true</span>
+ </pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">&#182;</a> </div> <p>Connect to exchanges</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">_connectExchanges</span><span class="o">:</span><span class="nf">(next) -&gt;</span>
+
+ <span class="nx">async</span><span class="p">.</span><span class="nx">forEach</span> <span class="nx">@_exchanges</span><span class="p">.</span><span class="nx">list</span><span class="p">(),</span> <span class="nx">@_connectExchange</span><span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="err">@</span><span class="p">),</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="o">=&gt;</span>
+ <span class="k">if</span> <span class="nx">err</span>
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s2">&quot;Couldn&#39;t connect to the exchanges: #{err.message}&quot;</span><span class="p">)</span>
+ <span class="k">return</span>
+
+ <span class="nx">next</span><span class="p">()</span>
+ </pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">&#182;</a> </div> <p>Exchange connection iterator</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">_connectExchange</span><span class="o">:</span><span class="nf">(exchange, callback) -&gt;</span>
+
+ <span class="nx">@conn</span><span class="p">.</span><span class="nx">exchange</span> <span class="nx">exchange</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span> <span class="nx">exchange</span><span class="p">.</span><span class="nx">options</span><span class="p">,</span> <span class="nf">(exchangeRef) -&gt;</span>
+ <span class="nv">exchange.ref = </span><span class="nx">exchangeRef</span>
+ <span class="nx">exchange</span><span class="p">.</span><span class="nx">openCallback</span><span class="p">(</span><span class="nx">exchangeRef</span><span class="p">)</span>
+
+ <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="kc">true</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-22">&#182;</a> </div> <p>Connect to queues</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">_connectQueues</span><span class="o">:</span><span class="nf">() -&gt;</span>
+
+ <span class="nx">async</span><span class="p">.</span><span class="nx">forEach</span> <span class="nx">@_queues</span><span class="p">.</span><span class="nx">list</span><span class="p">(),</span> <span class="nx">@_connectQueue</span><span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="err">@</span><span class="p">),</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="o">=&gt;</span>
+ <span class="k">if</span> <span class="nx">err</span>
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s2">&quot;Couldn&#39;t connect to the queues: #{err.message}&quot;</span><span class="p">)</span>
+ <span class="k">return</span>
+
+ <span class="nx">@_done</span><span class="p">()</span>
+ </pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-23">&#182;</a> </div> <p>Queue connection iterator</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">_connectQueue</span><span class="o">:</span><span class="nf">(queue, callback) -&gt;</span>
+
+ <span class="nx">@conn</span><span class="p">.</span><span class="nx">queue</span> <span class="nx">queue</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span> <span class="nx">queue</span><span class="p">.</span><span class="nx">options</span><span class="p">,</span> <span class="nf">(queueRef) -&gt;</span>
+ <span class="nv">queue.ref = </span><span class="nx">queueRef</span>
+
+ <span class="nx">queue</span><span class="p">.</span><span class="nx">openCallback</span><span class="p">(</span><span class="nx">queueRef</span><span class="p">)</span>
+
+ <span class="k">if</span> <span class="nx">queue</span><span class="p">.</span><span class="nx">exchangeName</span>
+ <span class="nx">queueRef</span><span class="p">.</span><span class="nx">bind</span> <span class="nx">queue</span><span class="p">.</span><span class="nx">exchangeName</span><span class="p">,</span> <span class="nx">queue</span><span class="p">.</span><span class="nx">routingKey</span>
+
+ <span class="k">if</span> <span class="nx">queue</span><span class="p">.</span><span class="nx">messageListener</span>
+ <span class="nx">queueRef</span><span class="p">.</span><span class="nx">subscribe</span> <span class="nx">queue</span><span class="p">.</span><span class="nx">sOptions</span><span class="p">,</span> <span class="nx">queue</span><span class="p">.</span><span class="nx">messageListener</span>
+
+ <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="kc">true</span><span class="p">)</span>
+ </pre></div> </td> </tr> <tr id="section-24"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-24">&#182;</a> </div> <p>When everything's connected, trigger the final callback</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">_done</span><span class="o">:</span><span class="nf">() -&gt;</span>
+
+ <span class="nv">msg =</span>
+ <span class="nv">queues : </span><span class="p">{}</span>
+ <span class="nv">exchanges : </span><span class="p">{}</span>
+ <span class="nv">connection : </span><span class="nx">@conn</span>
+
+ <span class="k">for</span> <span class="nx">k</span><span class="p">,</span><span class="nx">v</span> <span class="k">of</span> <span class="nx">@_queues</span><span class="p">.</span><span class="nx">index</span><span class="p">()</span>
+ <span class="nx">msg</span><span class="p">.</span><span class="nx">queues</span><span class="p">[</span><span class="nx">k</span><span class="p">]</span> <span class="o">=</span> <span class="nx">v</span><span class="p">.</span><span class="nx">ref</span>
+
+ <span class="k">for</span> <span class="nx">k</span><span class="p">,</span><span class="nx">v</span> <span class="k">of</span> <span class="nx">@_exchanges</span><span class="p">.</span><span class="nx">index</span><span class="p">()</span>
+ <span class="nx">msg</span><span class="p">.</span><span class="nx">exchanges</span><span class="p">[</span><span class="nx">k</span><span class="p">]</span> <span class="o">=</span> <span class="nx">v</span><span class="p">.</span><span class="nx">ref</span>
+
+ <span class="nx">@_callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">msg</span><span class="p">)</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
21 docs/AmqpExchange.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html> <html> <head> <title>AmqpExchange.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="example-advanced.html"> example-advanced.coffee </a> <a class="source" href="example-connection.html"> example-connection.coffee </a> <a class="source" href="example-simple.html"> example-simple.coffee </a> <a class="source" href="AmqpDsl.html"> AmqpDsl.coffee </a> <a class="source" href="AmqpExchange.html"> AmqpExchange.coffee </a> <a class="source" href="AmqpQueue.html"> AmqpQueue.coffee </a> <a class="source" href="IndexedList.html"> IndexedList.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> AmqpExchange.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>AMQP Exchange class for AMQP DSL</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">module.exports = </span><span class="k">class</span> <span class="nx">AmqpExchange</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <ul>
+<li><code>exchange( name, options )</code></li>
+<li><code>exchange( name, callback(exchange) )</code></li>
+<li><code>exchange( name, options, callback(exchange) )</code></li>
+</ul> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">constructor</span><span class="o">:</span><span class="nf">( @name, options, openCallback) -&gt;</span>
+ <span class="k">if</span> <span class="o">!</span><span class="nx">@name</span>
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s2">&quot;Exchange must have a name&quot;</span><span class="p">)</span>
+
+ <span class="vi">@options = </span><span class="p">{}</span>
+ <span class="vi">@openCallback = </span><span class="o">-&gt;</span>
+
+ <span class="k">if</span> <span class="k">typeof</span> <span class="nx">options</span> <span class="o">==</span> <span class="s2">&quot;function&quot;</span>
+ <span class="vi">@openCallback = </span><span class="nx">options</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="k">typeof</span> <span class="nx">options</span> <span class="o">==</span> <span class="s2">&quot;object&quot;</span>
+ <span class="vi">@options = </span><span class="nx">options</span>
+
+ <span class="k">if</span> <span class="k">typeof</span> <span class="nx">openCallback</span> <span class="o">==</span> <span class="s2">&quot;function&quot;</span>
+ <span class="vi">@openCallback = </span><span class="nx">openCallback</span>
+ </pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Real reference to an AQMP::Exchange object</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@ref = </span><span class="kc">null</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
30 docs/AmqpQueue.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html> <html> <head> <title>AmqpQueue.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="example-advanced.html"> example-advanced.coffee </a> <a class="source" href="example-connection.html"> example-connection.coffee </a> <a class="source" href="example-simple.html"> example-simple.coffee </a> <a class="source" href="AmqpDsl.html"> AmqpDsl.coffee </a> <a class="source" href="AmqpExchange.html"> AmqpExchange.coffee </a> <a class="source" href="AmqpQueue.html"> AmqpQueue.coffee </a> <a class="source" href="IndexedList.html"> IndexedList.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> AmqpQueue.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>AMQP Queue class for AMQP DSL</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">module.exports = </span><span class="k">class</span> <span class="nx">AmqpQueue</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <ul>
+<li><code>queue( name, options )</code></li>
+<li><code>queue( name, callback(queue) )</code></li>
+<li><code>queue( name, options, callback(queue) )</code></li>
+</ul> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">constructor</span><span class="o">:</span><span class="nf">( @name, options, openCallback) -&gt;</span>
+ <span class="k">if</span> <span class="o">!</span><span class="nx">@name</span>
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s2">&quot;Queue must have a name&quot;</span><span class="p">)</span>
+
+ <span class="vi">@options = </span><span class="p">{}</span>
+ <span class="vi">@openCallback = </span><span class="o">-&gt;</span>
+
+ <span class="k">if</span> <span class="k">typeof</span> <span class="nx">options</span> <span class="o">==</span> <span class="s2">&quot;function&quot;</span>
+ <span class="vi">@openCallback = </span><span class="nx">options</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="k">typeof</span> <span class="nx">options</span> <span class="o">==</span> <span class="s2">&quot;object&quot;</span>
+ <span class="vi">@options = </span><span class="nx">options</span>
+
+ <span class="k">if</span> <span class="k">typeof</span> <span class="nx">openCallback</span> <span class="o">==</span> <span class="s2">&quot;function&quot;</span>
+ <span class="vi">@openCallback = </span><span class="nx">openCallback</span>
+ </pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Real reference to an AMQP::Queue object</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@ref = </span><span class="kc">null</span>
+ </pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <ul>
+<li><code>.bind( name, routingKey )</code></li>
+</ul> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">bind</span><span class="o">:</span><span class="nf">( @exchangeName, @routingKey ) -&gt;</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <ul>
+<li><code>subscribe( callback(message, header, deliveryInfo) )</code></li>
+<li><code>subscribe( options, callback(message, header, deliveryInfo) )</code></li>
+</ul> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">subscribe</span><span class="o">:</span><span class="nf">( @sOptions, @messageListener ) -&gt;</span>
+ <span class="k">if</span> <span class="k">typeof</span> <span class="nx">@sOptions</span> <span class="o">==</span> <span class="s1">&#39;function&#39;</span>
+ <span class="vi">@messageListener = </span><span class="nx">@sOptions</span>
+ <span class="vi">@sOptions = </span><span class="p">{}</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
27 docs/IndexedList.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html> <html> <head> <title>IndexedList.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="example-advanced.html"> example-advanced.coffee </a> <a class="source" href="example-connection.html"> example-connection.coffee </a> <a class="source" href="example-simple.html"> example-simple.coffee </a> <a class="source" href="AmqpDsl.html"> AmqpDsl.coffee </a> <a class="source" href="AmqpExchange.html"> AmqpExchange.coffee </a> <a class="source" href="AmqpQueue.html"> AmqpQueue.coffee </a> <a class="source" href="IndexedList.html"> IndexedList.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> IndexedList.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Helper class for rapid access (create/append/read only)</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">module.exports = </span><span class="k">class</span> <span class="nx">IndexedList</span>
+
+ <span class="nx">constructor</span><span class="o">:</span><span class="nf">() -&gt;</span>
+ <span class="vi">@_index = </span><span class="p">{}</span>
+ <span class="vi">@_list = </span><span class="p">[]</span>
+
+ <span class="nv">get: </span><span class="nf">( key ) -&gt;</span>
+ <span class="nx">@_index</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">or</span> <span class="kc">false</span>
+
+ <span class="nv">set: </span><span class="nf">( key, value ) -&gt;</span>
+ <span class="nx">@_list</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">value</span><span class="p">)</span>
+ <span class="nx">@_index</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">value</span>
+ <span class="kc">null</span>
+
+ <span class="nv">length: </span><span class="o">-&gt;</span>
+ <span class="nx">@_list</span><span class="p">.</span><span class="nx">length</span>
+
+ <span class="nx">last</span><span class="o">:</span><span class="nf">() -&gt;</span>
+ <span class="nx">@_list</span><span class="p">[</span><span class="nx">@_list</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">or</span> <span class="kc">false</span>
+
+ <span class="nx">index</span><span class="o">:</span><span class="nf">() -&gt;</span>
+ <span class="nx">@_index</span>
+
+ <span class="nx">list</span><span class="o">:</span><span class="nf">() -&gt;</span>
+ <span class="nx">@_list</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
186 docs/docco.css
@@ -0,0 +1,186 @@
+/*--------------------- Layout and Typography ----------------------------*/
+body {
+ font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
+ font-size: 15px;
+ line-height: 22px;
+ color: #252519;
+ margin: 0; padding: 0;
+}
+a {
+ color: #261a3b;
+}
+ a:visited {
+ color: #261a3b;
+ }
+p {
+ margin: 0 0 15px 0;
+}
+h1, h2, h3, h4, h5, h6 {
+ margin: 0px 0 15px 0;
+}
+ h1 {
+ margin-top: 40px;
+ }
+#container {
+ position: relative;
+}
+#background {
+ position: fixed;
+ top: 0; left: 525px; right: 0; bottom: 0;
+ background: #f5f5ff;
+ border-left: 1px solid #e5e5ee;
+ z-index: -1;
+}
+#jump_to, #jump_page {
+ background: white;
+ -webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
+ -webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px;
+ font: 10px Arial;
+ text-transform: uppercase;
+ cursor: pointer;
+ text-align: right;
+}
+#jump_to, #jump_wrapper {
+ position: fixed;
+ right: 0; top: 0;
+ padding: 5px 10px;
+}
+ #jump_wrapper {
+ padding: 0;
+ display: none;
+ }
+ #jump_to:hover #jump_wrapper {
+ display: block;
+ }
+ #jump_page {
+ padding: 5px 0 3px;
+ margin: 0 0 25px 25px;
+ }
+ #jump_page .source {
+ display: block;
+ padding: 5px 10px;
+ text-decoration: none;
+ border-top: 1px solid #eee;
+ }
+ #jump_page .source:hover {
+ background: #f5f5ff;
+ }
+ #jump_page .source:first-child {
+ }
+table td {
+ border: 0;
+ outline: 0;
+}
+ td.docs, th.docs {
+ max-width: 450px;
+ min-width: 450px;
+ min-height: 5px;
+ padding: 10px 25px 1px 50px;
+ overflow-x: hidden;
+ vertical-align: top;
+ text-align: left;
+ }
+ .docs pre {
+ margin: 15px 0 15px;
+ padding-left: 15px;
+ }
+ .docs p tt, .docs p code {
+ background: #f8f8ff;
+ border: 1px solid #dedede;
+ font-size: 12px;
+ padding: 0 0.2em;
+ }
+ .pilwrap {
+ position: relative;
+ }
+ .pilcrow {
+ font: 12px Arial;
+ text-decoration: none;
+ color: #454545;
+ position: absolute;
+ top: 3px; left: -20px;
+ padding: 1px 2px;
+ opacity: 0;
+ -webkit-transition: opacity 0.2s linear;
+ }
+ td.docs:hover .pilcrow {
+ opacity: 1;
+ }
+ td.code, th.code {
+ padding: 14px 15px 16px 25px;
+ width: 100%;
+ vertical-align: top;
+ background: #f5f5ff;
+ border-left: 1px solid #e5e5ee;
+ }
+ pre, tt, code {
+ font-size: 12px; line-height: 18px;
+ font-family: Monaco, Consolas, "Lucida Console", monospace;
+ margin: 0; padding: 0;
+ }
+
+
+/*---------------------- Syntax Highlighting -----------------------------*/
+td.linenos { background-color: #f0f0f0; padding-right: 10px; }
+span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
+body .hll { background-color: #ffffcc }
+body .c { color: #408080; font-style: italic } /* Comment */
+body .err { border: 1px solid #FF0000 } /* Error */
+body .k { color: #954121 } /* Keyword */
+body .o { color: #666666 } /* Operator */
+body .cm { color: #408080; font-style: italic } /* Comment.Multiline */
+body .cp { color: #BC7A00 } /* Comment.Preproc */
+body .c1 { color: #408080; font-style: italic } /* Comment.Single */
+body .cs { color: #408080; font-style: italic } /* Comment.Special */
+body .gd { color: #A00000 } /* Generic.Deleted */
+body .ge { font-style: italic } /* Generic.Emph */
+body .gr { color: #FF0000 } /* Generic.Error */
+body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
+body .gi { color: #00A000 } /* Generic.Inserted */
+body .go { color: #808080 } /* Generic.Output */
+body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
+body .gs { font-weight: bold } /* Generic.Strong */
+body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
+body .gt { color: #0040D0 } /* Generic.Traceback */
+body .kc { color: #954121 } /* Keyword.Constant */
+body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */
+body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */
+body .kp { color: #954121 } /* Keyword.Pseudo */
+body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */
+body .kt { color: #B00040 } /* Keyword.Type */
+body .m { color: #666666 } /* Literal.Number */
+body .s { color: #219161 } /* Literal.String */
+body .na { color: #7D9029 } /* Name.Attribute */
+body .nb { color: #954121 } /* Name.Builtin */
+body .nc { color: #0000FF; font-weight: bold } /* Name.Class */
+body .no { color: #880000 } /* Name.Constant */
+body .nd { color: #AA22FF } /* Name.Decorator */
+body .ni { color: #999999; font-weight: bold } /* Name.Entity */
+body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
+body .nf { color: #0000FF } /* Name.Function */
+body .nl { color: #A0A000 } /* Name.Label */
+body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
+body .nt { color: #954121; font-weight: bold } /* Name.Tag */
+body .nv { color: #19469D } /* Name.Variable */
+body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
+body .w { color: #bbbbbb } /* Text.Whitespace */
+body .mf { color: #666666 } /* Literal.Number.Float */
+body .mh { color: #666666 } /* Literal.Number.Hex */
+body .mi { color: #666666 } /* Literal.Number.Integer */
+body .mo { color: #666666 } /* Literal.Number.Oct */
+body .sb { color: #219161 } /* Literal.String.Backtick */
+body .sc { color: #219161 } /* Literal.String.Char */
+body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */
+body .s2 { color: #219161 } /* Literal.String.Double */
+body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
+body .sh { color: #219161 } /* Literal.String.Heredoc */
+body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
+body .sx { color: #954121 } /* Literal.String.Other */
+body .sr { color: #BB6688 } /* Literal.String.Regex */
+body .s1 { color: #219161 } /* Literal.String.Single */
+body .ss { color: #19469D } /* Literal.String.Symbol */
+body .bp { color: #954121 } /* Name.Builtin.Pseudo */
+body .vc { color: #19469D } /* Name.Variable.Class */
+body .vg { color: #19469D } /* Name.Variable.Global */
+body .vi { color: #19469D } /* Name.Variable.Instance */
+body .il { color: #666666 } /* Literal.Number.Integer.Long */
View
46 docs/example-advanced.html
@@ -0,0 +1,46 @@
+<!DOCTYPE html> <html> <head> <title>example-advanced.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="example-advanced.html"> example-advanced.coffee </a> <a class="source" href="example-connection.html"> example-connection.coffee </a> <a class="source" href="example-simple.html"> example-simple.coffee </a> <a class="source" href="AmqpDsl.html"> AmqpDsl.coffee </a> <a class="source" href="AmqpExchange.html"> AmqpExchange.coffee </a> <a class="source" href="AmqpQueue.html"> AmqpQueue.coffee </a> <a class="source" href="IndexedList.html"> IndexedList.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> example-advanced.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="nv">AmqpDsl = </span><span class="nx">require</span> <span class="s1">&#39;amqp-dsl&#39;</span>
+
+
+<span class="nx">AmqpDsl</span>
+ <span class="p">.</span><span class="nx">login</span><span class="p">(</span>
+ <span class="nv">login: </span><span class="s1">&#39;legen&#39;</span>
+ <span class="nv">password: </span><span class="s1">&#39;waitforit&#39;</span>
+ <span class="nv">host: </span><span class="s1">&#39;dary&#39;</span>
+ <span class="nv">port: </span><span class="mi">2290</span>
+ <span class="nv">vhost: </span><span class="s1">&#39;/legendary&#39;</span>
+ <span class="p">)</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>Exchanges, queues and event listener can be declared wherever you want between <code>login</code> and <code>connect</code></p> </td> <td class="code"> <div class="highlight"><pre> <span class="p">.</span><span class="kc">on</span><span class="p">(</span><span class="s1">&#39;close&#39;</span><span class="p">,</span> <span class="nf">() -&gt;</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;Close &quot;</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">)</span>
+ <span class="p">.</span><span class="kc">on</span><span class="p">(</span><span class="s1">&#39;error&#39;</span><span class="p">,</span> <span class="nf">() -&gt;</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;Error &quot;</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">)</span>
+
+ <span class="p">.</span><span class="nx">queue</span><span class="p">(</span><span class="s1">&#39;test&#39;</span><span class="p">,</span> <span class="nx">passive</span><span class="o">:</span><span class="kc">false</span><span class="p">,</span> <span class="nf">(queue) -&gt;</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;Connected to Queue&quot;</span><span class="p">,</span> <span class="nx">queue</span><span class="p">.</span><span class="nx">name</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="s1">&#39;stream&#39;</span><span class="p">,</span> <span class="s1">&#39;#&#39;</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">subscribe</span><span class="p">(</span><span class="nf">(message, header, deliveryInfo) -&gt;</span> <span class="p">)</span>
+
+ <span class="p">.</span><span class="nx">queue</span><span class="p">(</span><span class="s1">&#39;queue2&#39;</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="s1">&#39;search&#39;</span><span class="p">,</span> <span class="s1">&#39;#&#39;</span><span class="p">)</span>
+
+ <span class="p">.</span><span class="nx">exchange</span><span class="p">(</span><span class="s1">&#39;stream&#39;</span><span class="p">,</span> <span class="nx">passive</span><span class="o">:</span><span class="kc">true</span><span class="p">,</span> <span class="nf">(exchange) -&gt;</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;Connected to Exchange&quot;</span><span class="p">,</span> <span class="nx">exchange</span><span class="p">.</span><span class="nx">name</span><span class="p">)</span>
+
+ <span class="p">.</span><span class="nx">exchange</span><span class="p">(</span><span class="s1">&#39;createdExchg&#39;</span><span class="p">)</span>
+
+ <span class="p">.</span><span class="nx">queue</span><span class="p">(</span><span class="s1">&#39;queue3&#39;</span><span class="p">,</span> <span class="nf">(queue)-&gt;</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;Connected to Queue&quot;</span><span class="p">,</span> <span class="nx">queue</span><span class="p">.</span><span class="nx">name</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="s1">&#39;createdExchg&#39;</span><span class="p">,</span> <span class="s1">&#39;#&#39;</span><span class="p">)</span>
+
+ <span class="p">.</span><span class="kc">on</span><span class="p">(</span><span class="s1">&#39;ready&#39;</span><span class="p">,</span> <span class="nf">() -&gt;</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;Connected to RabbitMQ&quot;</span><span class="p">)</span>
+
+ <span class="p">.</span><span class="nx">connect</span><span class="p">(</span><span class="nf">(err, amqp) -&gt;</span>
+
+ <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;Connected to #{Object.keys(amqp.exchanges).length} exchanges&quot;</span>
+ <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;Connected to #{Object.keys(amqp.queues).length} queues&quot;</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>All queues &amp; exchanges declared with AMQP-DSL can be accessible through amqp.queues &amp; amqp.exchanges</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">queue3 = </span><span class="nx">amqp</span><span class="p">.</span><span class="nx">queues</span><span class="p">.</span><span class="nx">queue3</span>
+
+ <span class="nx">queue3</span><span class="p">.</span><span class="nx">subcribe</span><span class="p">(</span><span class="nx">ack</span><span class="o">:</span><span class="kc">true</span><span class="p">,</span> <span class="nf">(message) -&gt;</span>
+ <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="nx">message</span>
+ <span class="nx">queue3</span><span class="p">.</span><span class="nx">shift</span><span class="p">()</span>
+ <span class="p">)</span>
+
+ <span class="nv">createdExchg = </span><span class="nx">amqp</span><span class="p">.</span><span class="nx">exchanges</span><span class="p">.</span><span class="nx">createdExchg</span>
+
+ <span class="nx">createdExchg</span><span class="p">.</span><span class="nx">publish</span><span class="p">(</span><span class="s2">&quot;routingKey&quot;</span><span class="p">,</span> <span class="nx">hello</span><span class="o">:</span><span class="s2">&quot;world&quot;</span><span class="p">)</span>
+
+ <span class="p">)</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
27 docs/example-connection.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html> <html> <head> <title>example-connection.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="example-advanced.html"> example-advanced.coffee </a> <a class="source" href="example-connection.html"> example-connection.coffee </a> <a class="source" href="example-simple.html"> example-simple.coffee </a> <a class="source" href="AmqpDsl.html"> AmqpDsl.coffee </a> <a class="source" href="AmqpExchange.html"> AmqpExchange.coffee </a> <a class="source" href="AmqpQueue.html"> AmqpQueue.coffee </a> <a class="source" href="IndexedList.html"> IndexedList.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> example-connection.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="nv">AmqpDsl = </span><span class="nx">require</span> <span class="s1">&#39;amqp-dsl&#39;</span>
+
+
+<span class="nx">AmqpDsl</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>First we log in, here the list of the available parameters and their default value</p>
+
+<pre><code>{
+ login: 'guest'
+ password: 'guest'
+ host: 'localhost'
+ port: 5672
+ vhost: '/'
+}
+</code></pre> </td> <td class="code"> <div class="highlight"><pre> <span class="p">.</span><span class="nx">login</span><span class="p">(</span>
+ <span class="nv">login: </span><span class="s1">&#39;user&#39;</span>
+ <span class="nv">password: </span><span class="s1">&#39;password&#39;</span>
+ <span class="nv">host: </span><span class="s1">&#39;localhost&#39;</span>
+ <span class="p">)</span>
+ </pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>We could do something else like creating <code>queues</code> or connecting to existing <code>exchange</code> (take a look at <code>example-simple.coffee</code> for that) but for now we just want to start the connection.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="p">.</span><span class="nx">connect</span><span class="p">(</span><span class="nf">(err, amqp) -&gt;</span>
+
+
+ <span class="k">if</span> <span class="nx">err</span>
+ <span class="k">throw</span> <span class="nx">err</span>
+ <span class="k">return</span>
+ </pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p><code>amqp.connections</code> == <code>[node-amqp::Connection]</code></p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s1">&#39;We are connected !&#39;</span>
+ <span class="p">)</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
59 docs/example-simple.html
@@ -0,0 +1,59 @@
+<!DOCTYPE html> <html> <head> <title>example-simple.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="example-advanced.html"> example-advanced.coffee </a> <a class="source" href="example-connection.html"> example-connection.coffee </a> <a class="source" href="example-simple.html"> example-simple.coffee </a> <a class="source" href="AmqpDsl.html"> AmqpDsl.coffee </a> <a class="source" href="AmqpExchange.html"> AmqpExchange.coffee </a> <a class="source" href="AmqpQueue.html"> AmqpQueue.coffee </a> <a class="source" href="IndexedList.html"> IndexedList.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> example-simple.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="nv">AmqpDsl = </span><span class="nx">require</span> <span class="s1">&#39;amqp-dsl&#39;</span>
+
+
+<span class="nx">AmqpDsl</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>First we log in, here the list of the available parameters and their default value</p>
+
+<pre><code>{
+ login: 'guest'
+ password: 'guest'
+ host:'localhost'
+ port: 5672
+ vhost: '/'
+}
+</code></pre> </td> <td class="code"> <div class="highlight"><pre> <span class="p">.</span><span class="nx">login</span><span class="p">(</span>
+ <span class="nv">login: </span><span class="s1">&#39;legen&#39;</span>
+ <span class="nv">password: </span><span class="s1">&#39;dary&#39;</span>
+ <span class="p">)</span>
+ </pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Bind listeners to some events (available events are <code>close</code>, <code>error</code> and <code>ready</code>)</p> </td> <td class="code"> <div class="highlight"><pre> <span class="p">.</span><span class="kc">on</span><span class="p">(</span><span class="s1">&#39;close&#39;</span><span class="p">,</span> <span class="nf">() -&gt;</span> <span class="nx">console</span><span class="p">.</span><span class="nx">error</span> <span class="s2">&quot;RabbitMQ connection closed&quot;</span><span class="p">)</span>
+ <span class="p">.</span><span class="kc">on</span><span class="p">(</span><span class="s1">&#39;error&#39;</span><span class="p">,</span> <span class="nf">(err) -&gt;</span> <span class="nx">console</span><span class="p">.</span><span class="nx">error</span> <span class="s2">&quot;RabbitMQ error&quot;</span><span class="p">,</span> <span class="nx">err</span><span class="p">)</span>
+ <span class="p">.</span><span class="kc">on</span><span class="p">(</span><span class="s1">&#39;ready&#39;</span><span class="p">,</span> <span class="nf">() -&gt;</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;Connected to RabbitMQ&quot;</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>We create a queue (<code>passive: false</code> see AMQP doc) with <code>.queue</code></p>
+
+<ul>
+<li><code>.queue( name, options )</code></li>
+<li><code>.queue( name, callback(queue) )</code></li>
+<li><code>.queue( name, options, callback(queue) )</code></li>
+</ul> </td> <td class="code"> <div class="highlight"><pre> <span class="p">.</span><span class="nx">queue</span><span class="p">(</span><span class="s1">&#39;testQueue&#39;</span><span class="p">,</span> <span class="nf">(queue) -&gt;</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;Connected to Queue&quot;</span><span class="p">,</span> <span class="nx">queue</span><span class="p">.</span><span class="nx">name</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>(optional) ... and bind that queue to an exchange with <code>.bind</code></p>
+
+<ul>
+<li><code>.bind( name, routingKey )</code></li>
+</ul> </td> <td class="code"> <div class="highlight"><pre> <span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="s1">&#39;stream&#39;</span><span class="p">,</span> <span class="s1">&#39;#&#39;</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>(optional) ... and subscribe for messages (without <code>ack</code> in this example)</p>
+
+<ul>
+<li><code>.subscribe( callback(message, header, deliveryInfo) )</code></li>
+<li><code>.subscribe( options, callback(message, header, deliveryInfo) )</code></li>
+</ul> </td> <td class="code"> <div class="highlight"><pre> <span class="p">.</span><span class="nx">subscribe</span><span class="p">(</span><span class="nf">(message, header, deliveryInfo) -&gt;</span> <span class="p">)</span>
+ </pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Create another queue <code>queue2</code> that will be binded to <code>search</code> exchange with the routing key <code>#.ok</code></p> </td> <td class="code"> <div class="highlight"><pre> <span class="p">.</span><span class="nx">queue</span><span class="p">(</span><span class="s1">&#39;queue2&#39;</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="s1">&#39;search&#39;</span><span class="p">,</span> <span class="s1">&#39;#.ok&#39;</span><span class="p">)</span>
+ </pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Connect to an existing queue <code>queue3</code></p> </td> <td class="code"> <div class="highlight"><pre> <span class="p">.</span><span class="nx">queue</span><span class="p">(</span><span class="s1">&#39;queue3&#39;</span><span class="p">,</span> <span class="nx">passive</span><span class="o">:</span><span class="kc">true</span><span class="p">,</span> <span class="nf">(queue)-&gt;</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;Connected to Queue&quot;</span><span class="p">,</span> <span class="nx">queue</span><span class="p">.</span><span class="nx">name</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>And now it's time to connect !
+<code>amqp</code> contains:</p>
+
+<ul>
+<li><code>amqp.connections</code> == <code>[node-amqp::Connection]</code></li>
+<li><code>amqp.queues</code> == <code>{}</code></li>
+<li><code>amqp.exchanges</code> == <code>{}</code></li>
+</ul> </td> <td class="code"> <div class="highlight"><pre> <span class="p">.</span><span class="nx">connect</span><span class="p">(</span><span class="nf">(err, amqp) -&gt;</span>
+
+ <span class="k">if</span> <span class="nx">err</span>
+ <span class="k">throw</span> <span class="nx">err</span>
+ <span class="k">return</span>
+
+ <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s1">&#39;We are connected !&#39;</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Do other stuff with <code>amqp</code> like subscribing to a queue</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">queue3 = </span><span class="nx">amqp</span><span class="p">.</span><span class="nx">queues</span><span class="p">.</span><span class="nx">queue3</span>
+
+ <span class="nx">queue3</span><span class="p">.</span><span class="nx">subscribe</span><span class="p">(</span><span class="nx">ack</span><span class="o">:</span><span class="kc">true</span><span class="p">,</span> <span class="nf">(message) -&gt;</span>
+ <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;Hey ! We got one new message !&quot;</span>
+ <span class="nx">queue3</span><span class="p">.</span><span class="nx">shift</span><span class="p">()</span>
+ <span class="p">)</span>
+
+ <span class="p">)</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
51 examples/example-advanced.coffee
@@ -0,0 +1,51 @@
+AmqpDsl = require 'amqp-dsl'
+
+
+AmqpDsl
+ .login(
+ login: 'legen'
+ password: 'waitforit'
+ host: 'dary'
+ port: 2290
+ vhost: '/legendary'
+ )
+
+ # Exchanges, queues and event listener can be declared wherever you want between `login` and `connect`
+
+ .on('close', () -> console.log "Close ", arguments)
+ .on('error', () -> console.log "Error ", arguments)
+
+ .queue('test', passive:false, (queue) -> console.log "Connected to Queue", queue.name)
+ .bind('stream', '#')
+ .subscribe((message, header, deliveryInfo) -> )
+
+ .queue('queue2')
+ .bind('search', '#')
+
+ .exchange('stream', passive:true, (exchange) -> console.log "Connected to Exchange", exchange.name)
+
+ .exchange('createdExchg')
+
+ .queue('queue3', (queue)-> console.log "Connected to Queue", queue.name)
+ .bind('createdExchg', '#')
+
+ .on('ready', () -> console.log "Connected to RabbitMQ")
+
+ .connect((err, amqp) ->
+
+ console.log "Connected to #{Object.keys(amqp.exchanges).length} exchanges"
+ console.log "Connected to #{Object.keys(amqp.queues).length} queues"
+
+ # All queues & exchanges declared with AMQP-DSL can be accessible through amqp.queues & amqp.exchanges
+ queue3 = amqp.queues.queue3
+
+ queue3.subcribe(ack:true, (message) ->
+ console.log message
+ queue3.shift()
+ )
+
+ createdExchg = amqp.exchanges.createdExchg
+
+ createdExchg.publish("routingKey", hello:"world")
+
+ )
View
31 examples/example-connection.coffee
@@ -0,0 +1,31 @@
+AmqpDsl = require 'amqp-dsl'
+
+
+AmqpDsl
+ # First we log in, here the list of the available parameters and their default value
+ #
+ # {
+ # login: 'guest'
+ # password: 'guest'
+ # host: 'localhost'
+ # port: 5672
+ # vhost: '/'
+ # }
+ #
+ .login(
+ login: 'user'
+ password: 'password'
+ host: 'localhost'
+ )
+
+ # We could do something else like creating `queues` or connecting to existing `exchange` (take a look at `example-simple.coffee` for that) but for now we just want to start the connection.
+ .connect((err, amqp) ->
+
+
+ if err
+ throw err
+ return
+
+ # `amqp.connections` == `[node-amqp::Connection]`
+ console.log 'We are connected !'
+ )
View
73 examples/example-simple.coffee
@@ -0,0 +1,73 @@
+AmqpDsl = require 'amqp-dsl'
+
+
+AmqpDsl
+# First we log in, here the list of the available parameters and their default value
+#
+# {
+# login: 'guest'
+# password: 'guest'
+# host:'localhost'
+# port: 5672
+# vhost: '/'
+# }
+#
+ .login(
+ login: 'legen'
+ password: 'dary'
+ )
+
+ # Bind listeners to some events (available events are `close`, `error` and `ready`)
+ .on('close', () -> console.error "RabbitMQ connection closed")
+ .on('error', (err) -> console.error "RabbitMQ error", err)
+ .on('ready', () -> console.log "Connected to RabbitMQ")
+
+ # We create a queue (`passive: false` see AMQP doc) with `.queue`
+ #
+ # * `.queue( name, options )`
+ # * `.queue( name, callback(queue) )`
+ # * `.queue( name, options, callback(queue) )`
+ .queue('testQueue', (queue) -> console.log "Connected to Queue", queue.name)
+
+ # (optional) ... and bind that queue to an exchange with `.bind`
+ #
+ # * `.bind( name, routingKey )`
+ .bind('stream', '#')
+
+ # (optional) ... and subscribe for messages (without `ack` in this example)
+ #
+ # * `.subscribe( callback(message, header, deliveryInfo) )`
+ # * `.subscribe( options, callback(message, header, deliveryInfo) )`
+ .subscribe((message, header, deliveryInfo) -> )
+
+ # Create another queue `queue2` that will be binded to `search` exchange with the routing key `#.ok`
+ .queue('queue2')
+ .bind('search', '#.ok')
+
+ # Connect to an existing queue `queue3`
+ .queue('queue3', passive:true, (queue)-> console.log "Connected to Queue", queue.name)
+
+ # And now it's time to connect !
+ # `amqp` contains:
+ #
+ # * `amqp.connections` == `[node-amqp::Connection]`
+ # * `amqp.queues` == `{}`
+ # * `amqp.exchanges` == `{}`
+ .connect((err, amqp) ->
+
+ if err
+ throw err
+ return
+
+ console.log 'We are connected !'
+
+ # Do other stuff with `amqp` like subscribing to a queue
+
+ queue3 = amqp.queues.queue3
+
+ queue3.subscribe(ack:true, (message) ->
+ console.log "Hey ! We got one new message !"
+ queue3.shift()
+ )
+
+ )
View
194 lib/AmqpDsl.js
@@ -0,0 +1,194 @@
+(function() {
+ var AmqpDsl, AmqpExchange, AmqpQueue, IndexedList, async;
+ var __slice = Array.prototype.slice;
+
+ async = require('async');
+
+ IndexedList = require('./IndexedList');
+
+ AmqpQueue = require('./AmqpQueue');
+
+ AmqpExchange = require('./AmqpExchange');
+
+ module.exports = AmqpDsl = (function() {
+ var LISTENNERS;
+
+ LISTENNERS = ['error', 'close', 'ready'];
+
+ AmqpDsl.login = function(opt) {
+ if (opt == null) opt = {};
+ return new AmqpDsl(opt);
+ };
+
+ function AmqpDsl(opt) {
+ if (opt == null) opt = {};
+ this._login = '';
+ this._password = '';
+ this._host = '';
+ this._port = 5672;
+ this._vhost = '/';
+ this._conn = null;
+ this._callback = function() {};
+ opt.login && (this._login = opt.login);
+ opt.password && (this._password = opt.password);
+ opt.host && (this._host = opt.host);
+ opt.port && (this._port = opt.port);
+ opt.vhost && (this._vhost = opt.vhost);
+ opt.login && (this._login = opt.login);
+ this._events = {};
+ this._exchanges = new IndexedList();
+ this._queues = new IndexedList();
+ }
+
+ AmqpDsl.prototype.on = function(event, listener) {
+ if (!~LISTENNERS.indexOf(event)) {
+ throw new Error("Event '" + event + "' is invalid");
+ }
+ if (!this._events[event]) this._events[event] = [];
+ this._events[event].push(listener);
+ return this;
+ };
+
+ AmqpDsl.prototype.exchange = function(name, options, openCallback) {
+ this._exchanges.set(name, new AmqpExchange(name, options, openCallback));
+ return this;
+ };
+
+ AmqpDsl.prototype.queue = function(name, options, openCallback) {
+ this._queues.set(name, new AmqpQueue(name, options, openCallback));
+ return this;
+ };
+
+ AmqpDsl.prototype.subscribe = function(options, messageListener) {
+ var queue;
+ queue = this._queues.last();
+ if (!queue) throw new Error("At least one queue must be declared");
+ queue.subscribe(options, messageListener);
+ return this;
+ };
+
+ AmqpDsl.prototype.bind = function(name, routingKey) {
+ var queue;
+ queue = this._queues.last();
+ if (!queue) throw new Error("At least one queue must be declared");
+ queue.bind(name, routingKey);
+ return this;
+ };
+
+ AmqpDsl.prototype.connect = function(amqp, _callback) {
+ this._callback = _callback;
+ if (typeof amqp === "function") {
+ this._callback = amqp;
+ amqp = require('amqp');
+ }
+ this._connect(amqp);
+ return null;
+ };
+
+ AmqpDsl.prototype._connect = function(amqp) {
+ var event, _results;
+ var _this = this;
+ this.conn = amqp.createConnection({
+ host: this._host,
+ port: this._port,
+ login: this._login,
+ password: this._password,
+ vhost: this._vhost
+ });
+ this.on('ready', function() {
+ return _this._connectExchanges(_this._connectQueues.bind(_this));
+ });
+ _results = [];
+ for (event in this._events) {
+ _results.push(this.conn.on(event, this._getListenerFor(event)));
+ }
+ return _results;
+ };
+
+ AmqpDsl.prototype._getListenerFor = function(event) {
+ var _this = this;
+ if (this._events[event].length === 1) {
+ return this._events[event][0];
+ } else {
+ return function() {
+ var args, listener, _i, _len, _ref;
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ _ref = _this._events[event];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ listener = _ref[_i];
+ listener.apply(null, args);
+ }
+ return true;
+ };
+ }
+ };
+
+ AmqpDsl.prototype._connectExchanges = function(next) {
+ var _this = this;
+ return async.forEach(this._exchanges.list(), this._connectExchange.bind(this), function(err) {
+ if (err) {
+ throw new Error("Couldn't connect to the exchanges: " + err.message);
+ return;
+ }
+ return next();
+ });
+ };
+
+ AmqpDsl.prototype._connectExchange = function(exchange, callback) {
+ return this.conn.exchange(exchange.name, exchange.options, function(exchangeRef) {
+ exchange.ref = exchangeRef;
+ exchange.openCallback(exchangeRef);
+ return callback(null, true);
+ });
+ };
+
+ AmqpDsl.prototype._connectQueues = function() {
+ var _this = this;
+ return async.forEach(this._queues.list(), this._connectQueue.bind(this), function(err) {
+ if (err) {
+ throw new Error("Couldn't connect to the queues: " + err.message);
+ return;
+ }
+ return _this._done();
+ });
+ };
+
+ AmqpDsl.prototype._connectQueue = function(queue, callback) {
+ return this.conn.queue(queue.name, queue.options, function(queueRef) {
+ queue.ref = queueRef;
+ queue.openCallback(queueRef);
+ if (queue.exchangeName) {
+ queueRef.bind(queue.exchangeName, queue.routingKey);
+ }
+ if (queue.messageListener) {
+ queueRef.subscribe(queue.sOptions, queue.messageListener);
+ }
+ return callback(null, true);
+ });
+ };
+
+ AmqpDsl.prototype._done = function() {
+ var k, msg, v, _ref, _ref2;
+ msg = {
+ queues: {},
+ exchanges: {},
+ connection: this.conn
+ };
+ _ref = this._queues.index();
+ for (k in _ref) {
+ v = _ref[k];
+ msg.queues[k] = v.ref;
+ }
+ _ref2 = this._exchanges.index();
+ for (k in _ref2) {
+ v = _ref2[k];
+ msg.exchanges[k] = v.ref;
+ }
+ return this._callback(null, msg);
+ };
+
+ return AmqpDsl;
+
+ })();
+
+}).call(this);
View
24 lib/AmqpExchange.js
@@ -0,0 +1,24 @@
+(function() {
+ var AmqpExchange;
+
+ module.exports = AmqpExchange = (function() {
+
+ function AmqpExchange(name, options, openCallback) {
+ this.name = name;
+ if (!this.name) throw new Error("Exchange must have a name");
+ this.options = {};
+ this.openCallback = function() {};
+ if (typeof options === "function") {
+ this.openCallback = options;
+ } else if (typeof options === "object") {
+ this.options = options;
+ }
+ if (typeof openCallback === "function") this.openCallback = openCallback;
+ this.ref = null;
+ }
+
+ return AmqpExchange;
+
+ })();
+
+}).call(this);
View
38 lib/AmqpQueue.js
@@ -0,0 +1,38 @@
+(function() {
+ var AmqpQueue;
+
+ module.exports = AmqpQueue = (function() {
+
+ function AmqpQueue(name, options, openCallback) {
+ this.name = name;
+ if (!this.name) throw new Error("Queue must have a name");
+ this.options = {};
+ this.openCallback = function() {};
+ if (typeof options === "function") {
+ this.openCallback = options;
+ } else if (typeof options === "object") {
+ this.options = options;
+ }
+ if (typeof openCallback === "function") this.openCallback = openCallback;
+ this.ref = null;
+ }
+
+ AmqpQueue.prototype.bind = function(exchangeName, routingKey) {
+ this.exchangeName = exchangeName;
+ this.routingKey = routingKey;
+ };
+
+ AmqpQueue.prototype.subscribe = function(sOptions, messageListener) {
+ this.sOptions = sOptions;
+ this.messageListener = messageListener;
+ if (typeof this.sOptions === 'function') {
+ this.messageListener = this.sOptions;
+ return this.sOptions = {};
+ }
+ };
+
+ return AmqpQueue;
+
+ })();
+
+}).call(this);
View
41 lib/IndexedList.js
@@ -0,0 +1,41 @@
+(function() {
+ var IndexedList;
+
+ module.exports = IndexedList = (function() {
+
+ function IndexedList() {
+ this._index = {};
+ this._list = [];
+ }
+
+ IndexedList.prototype.get = function(key) {
+ return this._index[key] || false;
+ };
+
+ IndexedList.prototype.set = function(key, value) {
+ this._list.push(value);
+ this._index[key] = value;
+ return null;
+ };
+
+ IndexedList.prototype.length = function() {
+ return this._list.length;
+ };
+
+ IndexedList.prototype.last = function() {
+ return this._list[this._list.length - 1] || false;
+ };
+
+ IndexedList.prototype.index = function() {
+ return this._index;
+ };
+
+ IndexedList.prototype.list = function() {
+ return this._list;
+ };
+
+ return IndexedList;
+
+ })();
+
+}).call(this);
View
28 package.json
@@ -0,0 +1,28 @@
+{
+ "name" : "amqp-dsl",
+ "description" : "Amqp-DSL - Fluent interface for node-amqp",
+ "keywords": ["amqp","dsl"],
+ "version": "1.0.0",
+ "homepage": "https://github.com/FGRibreau/node-amqp-dsl",
+ "repository": "git://github.com/FGRibreau/node-amqp-dsl.git",
+
+ "dependencies": {
+ "coffee-script":"1.0.0",
+ "async":"0.1.x",
+ "amqp":"0.1.x",
+ "docco":"0.3.x"
+ },
+
+ "devDependencies":{
+ "vows":"0.6.x"
+ },
+
+ "scripts": {
+ "test": "./node_modules/vows/bin/vows --spec"
+ },
+
+ "repository": "",
+ "author" : "Francois-Guillaume Ribreau <npm@fgribreau.com> (http://fgribreau.com)",
+ "main" : "lib/AmqpDsl",
+ "engines": { "node": ">= 0.4.12" }
+}
View
210 src/AmqpDsl.coffee
@@ -0,0 +1,210 @@
+# Amqp-DSL - Fluent interface for node-amqp
+
+async = require 'async'
+
+IndexedList = require './IndexedList'
+AmqpQueue = require './AmqpQueue'
+AmqpExchange = require './AmqpExchange'
+
+module.exports = class AmqpDsl
+
+ LISTENNERS =['error','close','ready']
+
+ ## Public API
+ #### require('amqp-dsl').login
+ # * `login( options = {} )`
+ #
+ AmqpDsl.login = (opt = {}) ->
+ new AmqpDsl(opt)
+
+ constructor:(opt = {}) ->
+
+ # Defaults
+ @_login = ''
+ @_password = ''
+ @_host = ''
+ @_port = 5672
+ @_vhost = '/'
+
+ @_conn = null
+ @_callback = ->
+
+ # Constructor arguments
+ opt.login and (@_login = opt.login)
+ opt.password and (@_password = opt.password)
+ opt.host and (@_host = opt.host)
+ opt.port and (@_port = opt.port)
+ opt.vhost and (@_vhost = opt.vhost)
+ opt.login and (@_login = opt.login)
+
+ # Events
+ @_events = {}
+
+ # Exchanges
+ @_exchanges = new IndexedList()
+
+ # Queues
+ @_queues = new IndexedList()
+
+ #### .on
+ # * `on( event, listener )`
+ on:( event, listener ) ->
+ if !~LISTENNERS.indexOf(event)
+ throw new Error("Event '#{event}' is invalid")
+
+ @_events[event] = [] if(!@_events[event])
+
+ @_events[event].push(listener)
+
+ this
+
+ #### .exchange
+ # * `.exchange( name, options )`
+ # * `.exchange( name, callback(exchange) )`
+ # * `.exchange( name, options, callback(exchange) )`
+ exchange:( name, options, openCallback ) ->
+ @_exchanges.set(name, new AmqpExchange(name, options, openCallback))
+ this
+
+ #### .queue
+ # * `.queue( name, options )`
+ # * `.queue( name, callback(queue) )`
+ # * `.queue( name, options, callback(queue) )`
+ queue:( name, options, openCallback ) ->
+ @_queues.set(name, new AmqpQueue(name, options, openCallback))
+ this
+
+ #### .queue(...).subscribe
+ # * `.subscribe( callback(message, header, deliveryInfo) )`
+ # * `.subscribe( options, callback(message, header, deliveryInfo) )`
+ subscribe:( options, messageListener ) ->
+ queue = @_queues.last()
+
+ throw new Error("At least one queue must be declared") if !queue
+
+ queue.subscribe(options, messageListener)
+ this
+
+ #### .queue(...).bind
+ # * `.bind( name, routingKey )`
+ bind:( name, routingKey ) ->
+ queue = @_queues.last()
+
+ throw new Error("At least one queue must be declared") if !queue
+
+ queue.bind(name, routingKey)
+ this
+
+ #### .connect
+ # * `.connect( amqp, callback(err, amqp) )`
+ # * `.connect( callback(err, amqp) )`
+ #
+ # `amqp` parameter is an hashtable which contain
+ #
+ # queues:
+ # sampleQueue:[Amqp::Queue]
+ #
+ # exchanges:
+ # sampleExchange:[Amqp::Exchange]
+ #
+ # connection: [Amqp::Connection]
+ #
+ connect:(amqp, @_callback)->
+
+ if typeof amqp is "function"
+ @_callback = amqp
+ amqp = require 'amqp'
+
+ @_connect(amqp)
+
+ null
+
+ ## Private API
+
+ # Create the connection to amqp and bind events
+ _connect:(amqp) ->
+ # Create connection
+ @conn = amqp.createConnection({
+ host: @_host,
+ port: @_port,
+ login: @_login,
+ password: @_password,
+ vhost: @_vhost
+ })
+
+ # When the connection will be ready, connect the exchanges
+ @on 'ready', () => @_connectExchanges(@_connectQueues.bind(this))
+
+ # Set event listeners
+ @conn.on(event, @_getListenerFor(event)) for event of @_events
+
+ # Return a listener fonction for the event `event`.
+ _getListenerFor: (event) ->
+
+ if @_events[event].length == 1
+ return @_events[event][0]
+ else
+ return (args...) =>
+ listener.apply(null, args) for listener in @_events[event]
+ true
+
+ # Connect to exchanges
+ _connectExchanges:(next) ->
+
+ async.forEach @_exchanges.list(), @_connectExchange.bind(@), (err) =>
+ if err
+ throw new Error("Couldn't connect to the exchanges: #{err.message}")
+ return
+
+ next()
+
+ # Exchange connection iterator
+ _connectExchange:(exchange, callback) ->
+
+ @conn.exchange exchange.name, exchange.options, (exchangeRef) ->
+ exchange.ref = exchangeRef
+ exchange.openCallback(exchangeRef)
+
+ callback(null, true)
+
+ # Connect to queues
+ _connectQueues:() ->
+
+ async.forEach @_queues.list(), @_connectQueue.bind(@), (err) =>
+ if err
+ throw new Error("Couldn't connect to the queues: #{err.message}")
+ return
+
+ @_done()
+
+ # Queue connection iterator
+ _connectQueue:(queue, callback) ->
+
+ @conn.queue queue.name, queue.options, (queueRef) ->
+ queue.ref = queueRef
+
+ queue.openCallback(queueRef)
+
+ if queue.exchangeName
+ queueRef.bind queue.exchangeName, queue.routingKey
+
+ if queue.messageListener
+ queueRef.subscribe queue.sOptions, queue.messageListener
+
+ callback(null, true)
+
+ # When everything's connected, trigger the final callback
+ _done:() ->
+
+ msg =
+ queues : {}
+ exchanges : {}
+ connection : @conn
+
+ for k,v of @_queues.index()
+ msg.queues[k] = v.ref
+
+ for k,v of @_exchanges.index()
+ msg.exchanges[k] = v.ref
+
+ @_callback(null, msg)
View
23 src/AmqpExchange.coffee
@@ -0,0 +1,23 @@
+# AMQP Exchange class for AMQP DSL
+module.exports = class AmqpExchange
+
+ # * `exchange( name, options )`
+ # * `exchange( name, callback(exchange) )`
+ # * `exchange( name, options, callback(exchange) )`
+ constructor:( @name, options, openCallback) ->
+ if !@name
+ throw new Error("Exchange must have a name")
+
+ @options = {}
+ @openCallback = ->
+
+ if typeof options == "function"
+ @openCallback = options
+ else if typeof options == "object"
+ @options = options
+
+ if typeof openCallback == "function"
+ @openCallback = openCallback
+
+ # Real reference to an AQMP::Exchange object
+ @ref = null
View
33 src/AmqpQueue.coffee
@@ -0,0 +1,33 @@
+# AMQP Queue class for AMQP DSL
+module.exports = class AmqpQueue
+
+ # * `queue( name, options )`
+ # * `queue( name, callback(queue) )`
+ # * `queue( name, options, callback(queue) )`
+ constructor:( @name, options, openCallback) ->
+ if !@name
+ throw new Error("Queue must have a name")
+
+ @options = {}
+ @openCallback = ->
+
+ if typeof options == "function"
+ @openCallback = options
+ else if typeof options == "object"
+ @options = options
+
+ if typeof openCallback == "function"
+ @openCallback = openCallback
+
+ # Real reference to an AMQP::Queue object
+ @ref = null
+
+ # * `.bind( name, routingKey )`
+ bind:( @exchangeName, @routingKey ) ->
+
+ # * `subscribe( callback(message, header, deliveryInfo) )`
+ # * `subscribe( options, callback(message, header, deliveryInfo) )`
+ subscribe:( @sOptions, @messageListener ) ->
+ if typeof @sOptions == 'function'
+ @messageListener = @sOptions
+ @sOptions = {}
View
26 src/IndexedList.coffee
@@ -0,0 +1,26 @@
+# Helper class for rapid access (create/append/read only)
+module.exports = class IndexedList
+
+ constructor:() ->
+ @_index = {}
+ @_list = []
+
+ get: ( key ) ->
+ @_index[key] or false
+
+ set: ( key, value ) ->
+ @_list.push(value)
+ @_index[key] = value
+ null
+
+ length: ->
+ @_list.length
+
+ last:() ->
+ @_list[@_list.length-1] or false
+
+ index:() ->
+ @_index
+
+ list:() ->
+ @_list
View
250 test/AmqpDsl-test.coffee
@@ -0,0 +1,250 @@
+#!/usr/bin/env node
+
+vows = require("vows")
+assert = require("assert")
+
+AmqpDsl = require("../src/AmqpDsl")
+
+suite = vows.describe("AmqpDsl test")
+suite.options.error = true
+
+
+suite.addBatch
+ ".login":
+ topic: -> AmqpDsl
+
+ "runs without issue": (cc) ->
+ assert.isObject cc.login()
+ assert.instanceOf cc.login(), AmqpDsl
+
+ "save options": (cc) ->
+ amqpdsl = cc.login(
+ login:'l'
+ password:'p'
+ host:'h'
+ port:10
+ vhost:'v'
+ )
+
+ assert.equal amqpdsl._login, 'l'
+ assert.equal amqpdsl._password, 'p'
+ assert.equal amqpdsl._host, 'h'
+ assert.equal amqpdsl._port, 10
+ assert.equal amqpdsl._vhost, 'v'
+
+ ".on":
+ topic: -> AmqpDsl.login()
+
+ "No events by default": (cc) ->
+ assert.equal Object.keys(cc._events).length, 0