This is a backend application for a Product Management System with asynchronous image processing. The application is built using Go and features RabbitMQ for message queuing, PostgreSQL for data storage, and local storage for compressed images.
- Add, retrieve, and filter products.
- Supports price range and product name filtering.
- Upload product images and process them asynchronously.
- Compress and store images locally.
- Update the database with paths to compressed images.
- Uses RabbitMQ for message queuing.
- Modular design with separate packages for database and queue handling.
product-management/
├── cmd/
│ └── main.go # Entry point for the application
├── pkg/
│ ├── api/
│ │ ├── handlers.go # HTTP API handlers
│ ├── database/
│ │ ├── db.go # PostgreSQL connection setup
│ ├── queue/
│ ├── queue.go # RabbitMQ connection and publishing logic
├── README.md # Project documentation
├── go.mod # Go module dependencies
└── go.sum # Checksums for module dependencies
- Go 1.18 or later
- PostgreSQL installed and running
- RabbitMQ installed and running (or use Docker)
- curl or Postman for API testing
1. Clone the Repository
git clone https://github.com/your-repo/product-management.git
cd product-management
2. Install Dependencies
go mod tidy
3. Set Up PostgreSQL
Create a new database:
postgres
CREATE DATABASE productdb;
Create tables:
sql
Copy code
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL
);
CREATE TABLE products (
id SERIAL PRIMARY KEY,
user_id INT REFERENCES users(id),
product_name VARCHAR(255) NOT NULL,
product_description TEXT,
product_images TEXT[], -- Array of image URLs
compressed_product_images TEXT[], -- Array of compressed URLs
product_price DECIMAL(10, 2)
);
4. Start RabbitMQ
Start RabbitMQ using Docker or your local installation:
docker run -d --name rabbitmq -p 5672:5672 rabbitmq:management
Start the Application
go run cmd/main.go
API Endpoints
| Method | Endpoint | Description |
|--------|------------------|--------------------------------------------|
| POST | `/products` | Create a new product |
| GET | `/products` | Retrieve all products with optional filters|
| GET | `/products/{id}` | Retrieve a product by ID |
| POST | `/process-images`| Process images asynchronously |
1. Create a Product
curl -X POST http://localhost:8080/products \
-H "Content-Type: application/json" \
-d '{
"user_id": 1,
"product_name": "Test Product",
"product_description": "A sample product.",
"product_images": ["http://example.com/image1.jpg", "http://example.com/image2.jpg"],
"product_price": 49.99
}'
2. Retrieve All Products
curl "http://localhost:8080/products?user_id=1&min_price=10&max_price=50&product_name=Sample"
3. Retrieve a Product by ID
curl "http://localhost:8080/products/1"
- Images are added to a RabbitMQ queue (image_processing) upon product creation.
- A microservice listens for messages, downloads images, compresses them, and stores the compressed versions locally.
- The compressed_product_images field in the database is updated with the paths of the compressed images.
- Language: Go
- Database: PostgreSQL
- Message Queue: RabbitMQ
- Local Storage: File system for image compression
- Add authentication and authorization for the API.
- Implement retry mechanisms for failed image processing tasks.
- Use cloud storage (e.g., S3) for compressed images.
- Implement a dead-letter queue for unprocessed messages.
- Full Name - Dhruv Kalra
- College - SRM Institute of Science & Technology
- Reg No - RA2111003030194
- Course - B.Tech
- Branch - Computer Science & Engineering