In this topic I will be setting up a Mqtt broker. This broker will be the center of the publish subsrcibe pattern being using in this and related topics. We need a few components to make this possible:
- The small device with client software (for publishing). For more information goto this topic
- A messaging protocol (used by the client software to either publish or subscribe)
- A broker (for managing the pub/sub data flows)
MQTT is a machine-to-machine (M2M)/”Internet of Things” connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium. For more information: http://mqtt.org/.
There is a list of clients and brokers available for Mqtt. In this case Mosquitto will be used: Mosquitto is an open source (BSD licensed) message broker that implements the MQ Telemetry Transport protocol version 3.1. MQTT provides a lightweight method of carrying out messaging using a publish/subscribe model. This makes it suitable for “machine to machine” messaging such as with low power sensors or mobile devices such as phones, embedded computers or microcontrollers like the Arduino. For more information: http://mosquitto.org/.
IBM provides different Mqtt solutions:
- IBM Integration Bus: IBM Integration Bus V9 has Telemetry feature built-in as optional licensed feature. IBM WebSphere MessageBroker V7 & V8 also include it as optionally licensed feature. Really Small Message Broker: 75KB MQTT broker runtime free download as binaries from IBM alphaWorks, RSMB is a C implementation of a tiny MQTT server suitable for development, embedded systems, concentrators or small to medium sized deployments. It provides complete MQTT v3.1 support, bridging, and a C client API
What is happening?
I am using CentOS: The CentOS Linux distribution is a stable, predictable, manageable and reproduceable platform derived from the sources of Red Hat Enterprise Linux (RHEL). We are now looking to expand on that by creating the resources needed by other communities to come together and be able to buld on the CentOS Linux platform. And today we start the process by delivering a clear governance model, increased transparency and access. In the coming weeks we aim to publish our own roadmap that includes variants of the core CentOS Linux.
To install Mosquitto on CentOS there is a very simple instruction on http://mosquitto.org/:
- Download the repository config file for your CentOS version (in my case 6.5) from below and copy it to /etc/yum.repos.d/ You’ll now be able to install and keep mosquitto up to date using the normal package management tools
- The available packages are: mosquitto, mosquitto-clients, libmosquitto1, libmosquitto-devel, libmosquittopp1, libmosquittopp-devel, python-mosquitto
- yum install these packages (as root do: yum install mosquitto mosquitto-clients libmosquitto1 libmosquitto-devel libmosquittopp1 libmosquittopp-devel python-mosquitto)
In case you are wondering what the repository config file looks like (you can give the file a logical name as long the file extension is .repo but do a chmod 644 and chown root:root on this file):
[home_oojah_mqtt] name=mqtt (CentOS_CentOS-6) type=rpm-md baseurl=http://download.opensuse.org/repositories/home:/oojah:/mqtt/CentOS_CentOS-6/ gpgcheck=1 gpgkey=http://download.opensuse.org/repositories/home:/oojah:/mqtt/CentOS_CentOS-6/repodata/repomd.xml.key enabled=1
After installing Mosquitto you can start the broker with:
- Open a terminal
- su – (you will be asked for the root user password)
- /etc/init.d/mosquitto start (for starting)
- /etc/init.d/mosquitto stop (for stopping)
After starting the broker, do a test with a publisher and subscriber client:
- Open a terminal
- mosquitto_sub -d -t hello/world (subscribe to topic hello/world)
- mosquitto_pub -d -t hello/world -m “Hello world” (publish “Hello world” with topic hello/world)
Basically this setup is not using any security but it enables you the publish Mqtt topics and subscribe to these with any Mqtt enabled client or device.