Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 9cead07052
Fetching contributors…

Cannot retrieve contributors at this time

72 lines (46 sloc) 1.719 kb

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 "JOBS.ONE", data
  done()

You can put more than one worker in the same file. It will only send you one job per worker registered.

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

# handler function
handleJobOne = (data, done) ->
  console.log "JOBS.ONE", data
  done()

# register 4 workers
myhub.worker 'jobs.one', handleJobOne
myhub.worker 'jobs.one', handleJobOne
myhub.worker 'jobs.one', handleJobOne
myhub.worker 'jobs.one', handleJobOne
Jump to Line
Something went wrong with that request. Please try again.