Skip to content

This is a mailbox system using Kafka that involves building a scalable and efficient messaging system where users can send, receive, and store messages.

Notifications You must be signed in to change notification settings

wnm-trojan/mailbox_api

Repository files navigation

Mailbox API

A simple FastAPI-based mailbox API for managing and sending emails. This mailbox system using Kafka involves building a scalable and efficient messaging system where users can send, receive, and store messages.

Features

  • Send emails via API endpoints
  • Manage mailbox data
  • FastAPI backend

Requirements

  • Python 3.8+
  • pip

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/mailbox_api.git
    cd mailbox_api
  2. Create a virtual environment (optional but recommended):

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies:

    pip install -r requirements.txt

Running the API

uvicorn main:app --reload

Configuration

  • Edit config.py or environment variables as needed for email settings.

Running Kafka and Redis (Cache)

To enable email queuing and caching, you may need to run Kafka and Redis:

Start Kafka (using Docker)

docker run -d --name kafka -p 9092:9092 -e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092 bitnami/kafka:latest

Note: You may also need to run Zookeeper:

docker run -d --name zookeeper -p 2181:2181 bitnami/zookeeper:latest

Start Redis (using Docker)

docker run -d --name redis -p 6379:6379 redis:latest

Make sure your application is configured to connect to these services as needed.

Running Kafka and Redis (Without Docker)

If you prefer not to use Docker, you can run Kafka and Redis directly on your system:

Install and Start Zookeeper

Kafka requires Zookeeper. Download and extract Apache Zookeeper:

tar -xzf apache-zookeeper-*.tar.gz
cd apache-zookeeper-*/
bin/zkServer.sh start

or

cd kafka_2.13-3.6.1
bin/zookeeper-server-start.sh config/zookeeper.properties

Install and Start Kafka

Download and extract Apache Kafka:

tar -xzf kafka_*.tgz
cd kafka_*/
bin/kafka-server-start.sh config/server.properties

or

cd kafka_2.13-3.6.1
bin/kafka-server-start.sh config/server.properties

Install and Start Redis

Install Redis using your package manager:

  • Ubuntu/Debian:
    sudo apt update
    sudo apt install redis-server
    sudo systemctl start redis
  • macOS (with Homebrew):
    brew install redis
    brew services start redis

Refer to the official documentation for more details on configuration and management.

Alembic Setup

Alembic is used for handling database migrations.

a. Install Alembic

pip install alembic
alembic init alembic

b. Configure Database URL

Edit alembic.ini and set your database URL:

sqlalchemy.url = postgresql://postgres:postgres@postgres:5432/mailbox_db

c. Create and Apply Migrations

Generate and apply your initial migration:

alembic revision --autogenerate -m "init schema"
alembic upgrade head

You need to run this app

Run it without docker (Using linux OS)

First you have to run kafka

cd kafka_2.13-3.6.1
bin/zookeeper-server-start.sh config/zookeeper.properties
cd kafka_2.13-3.6.1
bin/kafka-server-start.sh config/server.properties

Then you should start postgresql server and radis

    sudo systemctl start postgresql
    sudo systemctl start redis

Now You can run your FastApi App

  • Go to you python venv
    source venv/bin/activate
  • Run your app
    uvicorn app.main:app --reload

Then you should run your kafka consumer service

  • Go to you python venv and then
    python consumer_service.py

Now you test your FastApi mailbox app using below url

License

MIT License

About

This is a mailbox system using Kafka that involves building a scalable and efficient messaging system where users can send, receive, and store messages.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published