Skip to content

Latest commit

History

34 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Distributor

Resource based distribution of messages

What?

If you do SOA, you will probably get to a point where others need to be informed of changes to a certain resource. Distributor makes it easy.

How?

// producervarDistributor=require("distributor").Distributorvardistributor=newDistributor("amqp://localhost:5672","service_name","exchange_name")// orvardistributor=newDistributor({...amqpconnectionoptions...},"service_name","exchange_name")postsResoutce=distributor.register("posts")postsResource.publish({beep: "boop"})postsResource.publish({beep: "loop"},opts,function(err){})postsResource.registerSubTopic("comments")postsResource.publishComments({name: "Bob",message: "hi"})// get your resources outwriteFile("resourceDefinitions.json",distributor.getDefinition())// consumervarClient=require("distributor").Client// fetch your resource definitionvarresourceDefintions=readFile("resourceDefinitions.json")varclient=newClient(resourceDefinitions)// want a work queue?worker=client.posts.createWorker("shared_queue_name")worker.subscribe(function(msg,cb){// subscribe on the default topic, or specify another topic (routing key)// ack when donecb()})// or pub sub instead?worker=client.posts.createSubscriber()// doesn't take a name, exclusive queue to each clientworker.subscribe("service_name.posts.comments",function(msg,cb){cb()})// want a global worker insteadworker=client.createSubscriber()// subscribes to "service_name.#" by deafultworker.subscribe(function(msg,cb){cb()})

API

Distributor(connectionString,serviceName,exchangeName,connectionOpts)connectionString-eitheramqpconnectionString(amqp://..)oranoptionshashtobepassedtonode-amqpserviceName-thehighlevelnamefortheservice(usedwhencreatingthetopics)exchangeName-thenameoftheexchangeyouwanttouseconnectionOpts(notrequired)-extraoptionstopasstonode-amqpdistributor.registerresourceName,exchangeNameresourceName-thenameoftheresourcesthatyouwanttosendmessageson(posts,comments,etc)exchangeName(optional)-adifferentexchangetopublishtoo

Advanced

If you want to tweak default options/values to rabbitmq

vardistributor=require("distributor")distributor.defaults.publish.deliveryMode=1// changing ack behavior on a workerworker.onMessage=function(userHandlerFn){varself=this// don't require user to call back, auto ackreturnfunction(msg,headers,deliverInfo){userHandlerFnmsgself.queue.shift()}}

Defaults

Distributor defaults to reliability, which means publish and consumer confirms are enabled

Questions? Feature Requests?

Open a pull request!

License

MIT

About

resourceful distribution of messages through amqp

Resources

Stars

10 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages