node-bigqueue
A BigQueue module for node.js-based
apps
Installation
Install global & local dependencies.
$ [sudo] npm install -g coffee coffeegulp [docco]
$ npm install
Configuration
Module is self configured to point to a local instance of BigQueue. It uses the
node-config module, so you should
place your config files on ./config
folder in order to change the defaults.
Configuration Defaults
These are the default configuration values. More information on how override it
is available here.
---
bigqueue:
baseUri: 'http://127.0.0.1:8081'
producer:
postUri: '/messages'
defaultRetries: 3
defaultTimeout: 1000
consumer:
readUri: '/topics/#{topic}/consumers/#{consumer}/messages'
ackUri: '/topics/#{topic}/consumers/#{consumer}/messages/#{recipient}'
worker:
startDelay: 2000
sleepOnEmpty: 1000
sleepOnError: 2000
client:
processTimeout: 500
logger:
enabled: true
Running Tests
$ npm test
Gulp Tasks
$ coffeegulp [task = default]
lint -- run lint checks
test -- run tests
coffee -- compile scripts into .js
default -- perform all tasks above
docco -- generate docs
Usage
{Consumer, Producer} = require 'bigqueue'
Sending a Message
# Create Producer, with max_retries, timeout.
producer = new Producer 3, 2000
# Send 'hello world!' message.
producer.send 'cluster', ['test_topic', 'another'], 'hello world!'
.then(
(value) ->
console.log "message sent: #{JSON.stringify(value)}"
(error) ->
console.log "message failed: #{error}"
)
Fetching Messages
consumer = new Consumer 'cluster', 'test_consumer',
['test_topic', 'another']
consumer.on 'start', (consumer) ->
console.log "we're up and running!"
consumer.on 'stop', (consumer) ->
console.log 'stop!'
# Don't forget to notify Consumer whether we've been able to process the
# message or not!
consumer.on 'message', (message, ack) ->
console.log "got a message!: #{JSON.stringify(message)}"
# Process the message. We shouldn't take much time in here, otherwise we may
# timeout.
db.save message, (error) ->
ack(error)
consumer.on 'ack', (message) ->
console.log "message acknowledged!: #{message.recipientCallback}"
consumer.on 'uptodate', (consumer) ->
console.log "we're up to date!"
# Start consuming events.
consumer.start()