Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript Pub/Sub - Message Priorities

Tags:

javascript

More of a discussion than a question:

I've been reading an article titled 'Patterns For Large-Scale JavaScript Application Architecture' and so far it's been quite an eye opener.

The author of this article advocates the use of a pub/sub architecture with the use of a mediator/controller. There aren't any real-world examples given but on the actual slide show (http://addyosmani.com/blog/jqcon-largescalejs-2012/) he advocates using 'Amplify.js'.

Like many other pub/sub implementations Amplify supports message priorities. My understanding is that with a mediator in place the need for prioritising messages is diminished because the mediator takes control of what happens when and where. Is this a valid point?

Message priorities scare me because when the application grows (and varies) you could end up with a heap of modules all with different priorities set on their subscriptions and no real control over what's going on. Is this a valid concern or simply a misunderstanding of how they should actually be used?

like image 283
backdesk Avatar asked Mar 02 '12 09:03

backdesk


Video Answer


1 Answers

I would caution against using any complicated version of pub/sub. Instead of thinking in terms of priorities, think in terms of channels, and assume that all channels are handled independently of each other, and none of them have "priority".

Another caution: Don't use your module names as channel names or namespaces. If you do, you may as well be giving other modules a direct reference to your module and calling methods directly. The whole point is that your modules don't know about each other, and don't communicate directly.

One other tip: Don't tell other modules what to do. Instead, report events that have happened inside the module sending the message. That subtle shift in thinking is key to keeping modules decoupled.

like image 188
Eric Elliott Avatar answered Nov 14 '22 23:11

Eric Elliott