Getting started with InfluxDB with Python and MQTT (RabbitMQ)

Alex Karadimos
5 min readJul 31, 2019

Real time applications is a very hot topic right now, especially for Internet of Things, which is one of the biggest emerging tech industries. Real time Big Data are very important in other industries as well such as FinTech, InsurTech and the Automotive industry. I wanted to familiarize myself with these technologies and real-time applications in general, from the software/Cloud infrastructure perspective, and that’s why I decided to start this simple project to learn InfluxDB, a time-series database, and MQTT, a message based communication protocol. Time series DBs and the MQTT protocol are widely used in IoT solutions and real-time applications. I will also create a simple python script which will send (publish) some financial data which will then be stored and visualized in InfluxDB.

You can find the full code here https://github.com/karadalex/influxdb-mqtt-playground

Setting up the MQTT broker

We will first start by setting up a RabbitMQ server which is a message broker and also supports the MQTT protocol.

The fastest and easiest way to download, setup and run these is with Docker and Docker compose. If you haven’t installed these already, I totally recommend you to. Trust me it will be very handy for your future projects as well. Check out more about docker here https://docs.docker.com/

Most of the official images documentation describe how to configure and run the image with plain docker commands. I prefer to group these commands and all of the configuration in a single Docker compose file. The following is the docker-compose file I wrote, which will configure and run RabbitMQ

The credentials and other environment variables I like to store them in a separate file named .env which I also exclude from version control for security purposes. However I make a copy of that file and name it .env.example so that I can save and version control the changes in the .env schema. This is a good practice that I would…

Alex Karadimos

Electrical and Computer Engineer | Full Stack Web Developer, Robotics, Blockchain