This project sets up a real-time notification system using Kafka and Go. It demonstrates how to produce and consume messages in a Kafka-based architecture.
- Docker and Docker Compose
- Go programming language installed
curl(for Unix/Linux) or PowerShell (for Windows)
Open your terminal and run the following command to download the docker-compose.yml file:
curl -sSL https://raw.githubusercontent.com/bitnami/containers/main/bitnami/kafka/docker-compose.yml -o docker-compose.ymlOpen PowerShell and run the following command to download the docker-compose.yml file:
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/bitnami/containers/main/bitnami/kafka/docker-compose.yml" -OutFile "docker-compose.yml"Open the docker-compose.yml file in a text editor and replace the line:
KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://:9092with
KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092Navigate to the directory containing the docker-compose.yml file and run the following command to start the services:
docker-compose up -dCheck the running Docker containers to ensure Kafka and Zookeeper are up and running:
docker psYou should see containers for Kafka and Zookeeper running.
Navigate to the project directory and run the Go servers for the producer and consumer. Start the Producer:
go run cmd/producer/producer.goStart the Consumer:
go run cmd/consumer/consumer.goYou can send messages to the Kafka broker using curl or PowerShell.
To send a message indicating that Bruno started following:
curl -X POST http://localhost:8080/send -d "fromID=2&toID=1&message=Bruno started following you."To send a message indicating that Lena liked a post:
curl -X POST http://localhost:8080/send -d "fromID=4&toID=1&message=Lena liked your post: 'My weekend getaway!'"To send a message indicating that Bruno started following:
Invoke-RestMethod -Uri http://localhost:8080/send -Method Post -Body @{fromID='2'; toID='1'; message='Bruno started following you.'} -ContentType "application/x-www-form-urlencoded"To send a message indicating that Lena liked a post:
Invoke-RestMethod -Uri http://localhost:8080/send -Method Post -Body @{fromID='4'; toID='1'; message="Lena liked your post: 'My weekend getaway!'"} -ContentType "application/x-www-form-urlencoded"To retrieve notifications for a specific user (e.g., User 1), use the following curl command:
curl http://localhost:8081/notifications/1- Ensure Docker and Docker Compose are properly installed and running.
- Verify that your Go environment is set up correctly.
- Check the logs of your Kafka and Go services for any errors.
If you encounter any issues, please consult the documentation for Docker, Kafka, or the Go language, or reach out for community support.