Donwload Bitnami’s Kafka Docker image
curl -sSL \
https://raw.githubusercontent.com/bitnami/containers/main/bitnami/kafka/docker-compose.yml > docker-compose.yml
Before starting the Kafka broker, there’s a slight modification required in the docker-compose.yml file. Find the following string:
KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://:9092
And replace it with:
KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092
Run:
docker-compose up -d
Run the producer
go run cmd/producer/producer.go
Start the consumer
go run cmd/consumer/consumer.go
User 1 (Emma) receives a notification from User 2 (Bruno):
curl -X POST http://localhost:8080/send \
-d "fromID=2&toID=1&message=Bruno started following you."
User 2 (Bruno) receives a notification from User 1 (Emma):
curl -X POST http://localhost:8080/send \
-d "fromID=1&toID=2&message=Emma mentioned you in a comment: 'Great seeing you yesterday, @Bruno!'"
User 1 (Emma) receives a notification from User 4 (Lena):
curl -X POST http://localhost:8080/send \
-d "fromID=4&toID=1&message=Lena liked your post: 'My weekend getaway!'"
Retrieving notifications for User 1 (Emma):
curl http://localhost:8081/notifications/1