Skip to content

The MQTT Protocol

This document provides a brief overview of MQTT, the message transmission protocol used by NeuroScale.

Introduction

Our overview so far has covered the key concepts important for an understanding of how NeuroScale works. At this point it should be clear that through the API, a developer can select various pipelines and deploy these as running instances for the purpose of brain state decoding. NeuroScale instances have been highly optimised to perform this processing quickly and reliably. However, there still remains the issue of how, precisely, should a developer send and receive data from the instances established through the use of the NeuroScale API. As touched upon earlier, a publish/subscribe model is used and the specific message transmission protocol we support is MQTT. In this document, we give a brief introduction to MQTT that should help clarify the basic concepts you will need to know as a NeuroScale user and developer.

Why MQTT?

The Message Queuing Telemetry Transport (MQTT) protocol is an implementation of a software architectural design commonly referred to as a publish/subscribe messaging pattern. This pattern is very useful for decoupling the different components of a client-server system facilitating robust system design. From the point of view of a NeuroScale developer, this pattern means that the output of your computation may not only be consumed by the sending client but by any number of authorised consumers. The decoupling provided by MQTT means that this distribution of output does not need to be managed by the sending client and thus simplifies the implementation of dynamic network topologies and state sharing designs. MQTT also provides a very lightweight protocol and has been designed for situations where bandwidth is at a premium. As a consequence, transmission overhead is low and this helps reduce round-trip times on NeuroScale. Finally, MQTT supports message filtering, a process by which subscribers only receive a subset of messages published. This filtering, in MQTT, is achieved through a named logical channel system commonly referred to as a topic-based system. Topics in MQTT are syntactically represented in a hierarchical or directory structure with a slash / symbol used to separate topics into subtopics at a number of levels. Subscribing entities can filter according to these topic criteria and in so doing gain fine control over which messages they will receive.

MQTT Topics in NeuroScale

Let's revisit our streaming endpoint examples from our earlier document:

mqtt://streaming.neuroscale.io:443/maiYbX8nrBdWPStj82G4Xb/in
mqtt://streaming.neuroscale.io:443/maiYbX8nrBdWPStj82G4Xb/out

These resources expressed as URI may now make a little more sense. MQTT is specified as the transport protocol (and in this case 443 is the port number) and the unique specific MQTT topic for streaming your data to is the path of the first URI (namely, /maiYbX8nrBdWPStj82G4Xb/in), while you read the result from the path of the second URI (/maiYbX8nrBdWPStj82G4Xb/out). In more advanced uses of NeuroScale you will see that pipelines with multiple outputs can be filtered according to specific outputs via a subtopic approach. So now we can interpret these NeuroScale resources as MQTT topics and therefore all that is left to learn is how to integrate MQTT into your application codebase.

MQTT Libraries

Thankfully there are many client MQTT libraries available. We recommend the use of the Paho project to source your client libraries for MQTT. It contains many robust and tested implementations in C/C++, Java, JavaScript, Python, Go and C#. There are also many tutorials online. We will also demonstrate through tutorials and ready to go runnable sample code elsewhere on this site how to get started with all of this.