Assignment based on MQTT for Empello, London (https://www.empello.com)
Create a simple "Hello World" MQTT PUB/SUB app.
- Subscriber should listen to the topic
/test
- First publisher, with
/test/hello
sends "hello" every 1 second (feel free to use time.sleep(1)) - Second publisher, with the
/test/world
sends "world" every 2 second. - Please use this package: paho-mqtt
For a no-setup broker, feel free to use the one at https://mosquitto.org
Create a docker file with a working Django setup. What do you need to do to make it production-ready?
- linux os (with bash shell)
- Python 3.x
- virtualenv
- test.mosquitto.org
-
Clone the project
git clone https://github.com/KetanSingh11/mqtt-empello-assignment.git
-
Open 2 tabs in linux terminal, and navigate to the project directory.
-
In Tab #1 - run
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
-
In Tab #1 (subscriber) - run the command (the subscriber will start and wait for messages):
python subscriber.py
-
In Tab #2 (publisher) - run the below command in order:
source venv/bin/activate
chmod +x run.sh
./run.sh
-
Messages will start showing up in the Tab #1.
By default the publisher sends 5 messages and then shutsdown. To change this, update the value of
send_msg_count
in thepublisher.py
file to a integer number.