azlaanmsamad / Inria_Task

MIT License
0 stars 0 forks source link

Inria Task

This Repository contains Web Development Task to be completed as a part of the Inria selection Procedure.

Progress

Problem Statement

Sequence Diagram

  sequenceDiagram
    participant UI  
    participant WebApp
    participant Sensor_1
    participant Sensor_2
    participant Sensor_3
    participant Message Broker
    participant Consumer_1
    participant Consumer_2
    participant Consumer_3
    participant Database 

    UI->>WebApp : HTTP POST Request Input user's name
    WebApp-->>UI : Response OK
    WebApp->>Sensor_1 : Forward Request 1
    WebApp->>Sensor_2 : Forward Request 2
    WebApp->>Sensor_3 : Forward Request 3
    Sensor_1->>Message Broker: Send Message 1
    Sensor_2->>Message Broker: Send Message 2
    Sensor_3->>Message Broker: Send Message 3
    Message Broker->>Consumer_1: Consume Messgae 1
    Message Broker->>Consumer_2: Consume Messgae 2
    Message Broker->>Consumer_3: Consume Messgae 3
    Consumer_1-->>Message Broker: Acknowledge
    Consumer_2-->>Message Broker: Acknowledge
    Consumer_3-->>Message Broker: Acknowledge

    Consumer_1->>Database : Store Username
    Database-->>Consumer_1 : Response OK

    Consumer_2->>Database : Clear Username
    Database-->>Consumer_2 : Response OK

    Consumer_3->>Database : Update Username
    Database-->>Consumer_3 : Response OK

RabbitMQ

RabbitMQ Docker Launch

  1. Install docker
  2. Open the terminal and go to the rabbitmq/ directory.
  3. Run docker compose up in the terminal.
  4. Open the web browser and enter http://localhost:15672 to get the login page.
  5. Enter the username as guest and password as guest as well.

RabbitMQ Understanding

RabbitMQ Usage:

  1. After logging in the browser, click on Exchanges tab, and select exchanger from the list of exchanges.
  2. Expand the Bindings drop down menu to see the different queues and associated Routing key.
  3. Go to Publish message drop down and type the Routing key of the associated Queue.
  4. Type the message you wish to send in the Payload section and finally click on Publish message. You will get a message published pop up window, close it.
  5. Ideally, if you entered the Routing key for sensor_1 the messgae should have been received by sensor_1 only and no other queue since its a direct exchange.
  6. To check this, go to the Queues tab select the sensor_1 queue and expand the Get messages drop section and click on Get Messages(s) button.
  7. The message in the payload should be the same as you sent in Step 4. And this message should not exist in other queues, repeat the steps 6-7 to confirm this.

Flask Web App

Web App Installation

  1. First install all the requirements pip install -r requirements.txt
  2. Execute the command python run.py in the terminal.
  3. Open a web browser and go to http://127.0.0.1:5000/

Web App Usage

  1. After opening the browser a welcome page is displayed.
  2. To add a user's name go to the Register tab and add the name. This will also store it in the in-memory database.
  3. The top 5 most recent added Users can be checked by clicking the Users (In Memory) icon.
  4. Finally, another REST API is used which clears all the data by clicking on Clear button.

Technologies Used:

Flask, RabbitMQ/Redis, SQLAlchemy

LICENSE

MIT LICENSE