node.js - implementing pubsub between different node processes -


i'm writing nodejs based rest api.

my api have different methods put /friends adds user friend list of logged in user.

i want notify other user, has been added friend, via different methods (push notification, mail, whatever). dont want notification inside api process, instead want publish events nodejs process (might running on different machine), pickup , notification work.

what accepted methods implement such architecture? key here want pub/sub pattern between different nodejs processes might not share same machine, guess regular eventemitter wont there.

thanks help!

  1. the first thing came mind use @substack's dnode project. wrote blog post few years ago adapting dnode, javascript-based rpc framework, pubsub framework. details here: http://substack.net/roll_your_own_pubsub_with_dnode

  2. it seems faye becoming popular, can spin node.js server acts message manager.

  3. additionally may @ using socket.io , redis described here.

you try eliminating infrastructure overhead using external real-time network pubnub. pubnub free 20 daily devices (see pricing page.) have examples on node.js api github page, basic structure is:

var pubnub = require("pubnub").init({     publish_key   : "demo",     subscribe_key : "demo" });  pubnub.subscribe({     channel  : "my_channel",     callback : function(message) {         console.log( "friend request notice: ", message );     } }); 

to send messages, can use similar publish.

pubnub.publish({     channel : "my_channel",     message : 'you friends bob.' }); 

this simpler working , validate pub/sub model you're choosing (potentially) multiple servers. luck!


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -