messagehub

Simple message, queue and pubsub system compatible with RabbitMQ

messagehub

Simple message, queue and pubsub system compatible with RabbitMQ.

Communicates events and jobs across processes and servers.

npm install messagehub

You also need to connect to a running RabbitMQ server at the host specified.

messagehub = require 'messagehub'
myhub = messagehub 'localhost', 'mychannel'

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

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()