Skip to content

Instantly share code, notes, and snippets.

@iAmNathanJ
Last active May 11, 2016 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iAmNathanJ/bc94f2fc4050c0d334711db4073fc4b0 to your computer and use it in GitHub Desktop.
Save iAmNathanJ/bc94f2fc4050c0d334711db4073fc4b0 to your computer and use it in GitHub Desktop.
Pub Sub Notes

Publish Subscribe

  • Some similarities to Observer and Observable pattern(s)
  • Could you use an Oberserver implementation as the middle of a pub/sub implementation? ie Publisher -> Observer -> Subscribers

Problems

  • Order of subscribes and publish makes for bootstrapping/bootup order requirements. Inexplicit coupling that's hard to debug
  • Data is the coupling - how to version?

Decisions on When to Use

  • Informational only
  • If you need certainty, acknowledgement is needed. (By directional messages?)
  • Discrete parts of a system - allow scaling of team(s) so each work on their own part given a contract

Implementations

  • Pusherapp
  • Pubnub
  • npm: pubsub-js (and the other 10m)
/* the PubSub module keeps a list of functions that listen for event */
PubSub.subscribe('eventName', function(eventInfo) {
console.log(`the ${eventInfo.type} event was published.`);
});
PubSub.publish('eventName', data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment