This project demonstrates a real-time notification system built with Go and Apache Kafka. It consists of a producer that sends notifications and a consumer that receives and stores them.
Prerequisites
Go (1.23.2 or later)
Docker and Docker Compose
curl (for testing)
Setup
Clone the repository:
git clone https://github.com/afzalhussain23/kafka-notify.git
cd kafka-notify
Start the Kafka broker:
docker compose up -d
Install the required Go packages:
go mod tidy
Running the Application
Start the producer:
go run cmd/producer/producer.go
The producer will start on http://localhost:8080.
In a new terminal, start the consumer:
go run cmd/consumer/consumer.go
The consumer will start on http://localhost:8081.
Testing the System
Send a notification:
curl -X POST http://localhost:8080/send \
-d "fromID=2&toID=1&message=Bruno started following you."
Retrieve notifications for a user:
curl http://localhost:8081/notifications/1
Project Structure
cmd/producer/producer.go: Contains the Kafka producer and API endpoint for sending notifications.
cmd/consumer/consumer.go: Contains the Kafka consumer and API endpoint for retrieving notifications.
pkg/models/models.go: Defines the data models used in the application.