Pub-Sub

sub-beer

Nope... Nothing to do with beer nor with underwater exploration!

The Publish-Subscribe pattern is a system where subscribers listen to a particular topic and publishers send messages with that topic. Nothing is send directly from publishers to subscribers. This give a great degree of flexibility.

Illustration of the concept from pubsub.sourceforge.net

Application

Why I am talking about this? Simply because if the monolithic application works perfectly. Any change in configuration and/or programme impose a restart (the same way a crash/exception on one thread would break everything).

This is the reason why I am on the path of breaking up all threads into separate processes. Obsviously there is a bit of overhead but I rely on shared libraries to aleviate the waste of memory.

One of the major issues is that all parts now need to communicate between them as they can't share variables any more.

Redis

My first prototypes were using Redis, for storage of value and because it implements a pubsub set of functions. It is a minimalist implementation (no QoS, no bells and whistles) but worked very well.

MQTT

Yet, the most common pub-sub protocol these days seems something called MQTT (used to be an acronym) which is now a OASIS standard for Machine2Machine data sharing. My first thought was that it might be a little bit overkill for interprocess communication but it certainly opens a whole new world.

There are loads of cloud based MQTT brokers (if needed) and you find MQTT libraries for Arduino, etc...

More about it in a next post...