Skip to content
Browse files

added url and options support

  • Loading branch information...
1 parent 9cead07 commit fbe38b1e3cc798fe7af23c6c46bebd8a1984cc28 @seanhess seanhess committed Sep 26, 2012
Showing with 34 additions and 3 deletions.
  1. +2 −0 README.md
  2. +8 −2 index.coffee
  3. +1 −1 package.json
  4. +23 −0 test.coffee
View
2 README.md
@@ -22,6 +22,8 @@ Documentation
messagehub = require 'messagehub'
myhub = messagehub 'localhost', 'mychannel'
+You can also send an AMQP url as the first parameter, or the options hash [as describe here](https://github.com/postwait/node-amqp#connection-options-and-url).
+
### Events
Emit an event
View
10 index.coffee
@@ -39,7 +39,13 @@ events = require 'events'
# EXCHANGE TYPE
-module.exports = hub = (host, channel, cb) ->
+module.exports = hub = (optionsOrUrl, channel, cb) ->
+
+ options = if optionsOrUrl.length?
+ url = optionsOrUrl
+ url = if url.match "amqp" then url else "amqp://" + url
+ {url}
+ else optionsOrUrl
cb ?= ->
@@ -48,7 +54,7 @@ module.exports = hub = (host, channel, cb) ->
exchange = null
- connection = amqp.createConnection { host: host }
+ connection = amqp.createConnection options
connection.on 'error', (err) ->
if err? then throw new Error "Could not connect to RabbitMQ server at #{host}"
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "messagehub",
- "version": "0.0.1",
+ "version": "0.0.2",
"description": "Simple message, queue and pubsub system compatible with RabbitMQ",
"main": "index.js",
"scripts": {
View
23 test.coffee
@@ -11,6 +11,27 @@ describe 'hub', ->
cb hub
randomName = -> Math.random().toString(26).replace("0.", "")
+
+
+ describe 'connection string', ->
+ it 'should take an options hash', (done) ->
+ hub {host:"localhost"}, "test2", (err, hub) ->
+ assert.ifError err
+ assert.ok hub
+ done()
+
+ it 'should take a host', (done) ->
+ hub "localhost", "test2", (err, hub) ->
+ assert.ifError err
+ assert.ok hub
+ done()
+
+ it 'should take a url', (done) ->
+ hub "amqp://localhost", "test2", (err, hub) ->
+ assert.ifError err
+ assert.ok hub
+ done()
+
describe 'events', ->
it 'should emit an event', (done) ->
newHub (hub) ->
@@ -267,3 +288,5 @@ describe 'hub', ->
+
+

0 comments on commit fbe38b1

Please sign in to comment.
Something went wrong with that request. Please try again.