messagehub
v0.0.2
Published
Simple message, queue and pubsub system compatible with RabbitMQ
Downloads
1
Readme
messagehub
Simple message, queue and pubsub system compatible with RabbitMQ.
Communicates events and jobs across processes and servers.
Installation
npm install messagehub
You also need to connect to a running RabbitMQ server at the host specified.
Documentation
Create
messagehub = require 'messagehub'
myhub = messagehub 'localhost', 'mychannel'
Events
Emit an event
messagehub = require 'messagehub'
myhub = messagehub 'localhost', 'mychannel'
myhub.emit 'messages.one', {key: "value"}
Observe an event (ALL handlers will trigger)
messagehub = require 'messagehub'
myhub = messagehub 'localhost', 'mychannel'
myhub.on 'messages.one', (data) ->
console.log "MESSAGES.ONE", data
Jobs
Queue a job
messagehub = require 'messagehub'
myhub = messagehub 'localhost', 'mychannel'
myhub.job 'jobs.one', {key: "value"}
Handle a job (jobs are balanced between workers)
messagehub = require 'messagehub'
myhub = messagehub 'localhost', 'mychannel'
myhub.worker 'jobs.one', (data, done) ->
console.log "MESSAGES.ONE", data
done()