Git Product home page Git Product logo

msgqueue_app's Introduction

Simple message queue application

Switchdin challenge for Python Software Engineer (Embedded, Data Science)

Application Description

Environment setup:

  • MQTT message broker: RabbitMQ
  • Publish/Subscribe library: paho-mqtt

System overview: System overview

Broker local setup

Initialise RabbitMQ server:

# Starting server
rabbitmq-server

# Enabling plugin
rabbitmq-plugins enable rabbitmq_mqtt

# Setup users and authentication
rabbitmqctl add_user mqtt-test mqtt-test
rabbitmqctl set_permissions -p / mqtt-test ".*" ".*" ".*"
rabbitmqctl set_user_tags mqtt-test management

Generate hidden environment file (secret keys)

  • File name: .env
  • File content:
MQTT-USERNAME = "mqtt-test"
MQTT-PASSWORD = "mqtt-test"

Configure host:

  • Modify host in config.json to "localhost".

Broker cloud setup (AWS EC2 with docker)

Prerequisite: Installation Docker on Linux (for AWS EC2) -> read here

docker pull rabbitmq
sudo docker run -d -p 1883:1883 rabbitmq:latest
sudo docker container ps
# grab container name
sudo docker exec -it <container_name> sh

# <!-- Inside container --!>
rabbitmq-plugins enable rabbitmq_mqtt
rabbitmqctl add_user mqtt-test mqtt-test
rabbitmqctl set_permissions -p / mqtt-test ".*" ".*" ".*"
rabbitmqctl set_user_tags mqtt-test management
exit
# <!-- End container --!>

Configure host:

  • Modify host in config.json to AWS EC2's public IP address.

Open port of AWS EC2:

  • Security group > Inbound rules > IPv4 > "All traffic" (all protocol, all port range, source=0.0.0.0/0) (for demo only, not a good practice to open all the ports and inbound)

App1

Generates a random number between [1 and 100] every [1 to 30] seconds and publishes to broker with topic named app1/randint.

Run app:

cd src
python ./app1.py

App2

Subscribes to topic app1/randint and compute average every [1, 5, 30] minutes, and publishes accordingly to broker with topics named app2/stat_1m, app2/stat_5m, app2/stat_30m.

Run app:

cd src
python ./app2.py

App3

Subscribes to topics app2/stat_1m, app2/stat_5m, app2/stat_30m, and prints out tabular view in console accordingly.

Run app:

cd src
python ./app3.py

Demo

demo

Project timeline records

  • Self-study & research: 1.5 day
  • Implementation: 1 day
    • Design: 30 minutes
    • Coding: 2 hours
    • Testing (local): 1 hour
    • Deployment: 2 hour
    • Testing (deploy): 1 hour
    • Documentation: 1 hour

References

  1. RabbitMQ:
  2. Paho MQTT:
  3. Install docker on Linux:

msgqueue_app's People

Contributors

hhodac avatar

Stargazers

Eldar Kurmakaev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.