This project demonstrates the implementation publish-subscribe messaging pattern using Redis as message broker. The project contains code examples of publisher & subsciber service written in Go language.
- Please make sure you have Go installed on your system.
- Please make sure you have Docker installed on your system.
- Please make sure you have Docker Compose installed on your system.
- Clone this repository to your local machine using terminal.
git clone https://github.com/mushoffa/redis-pubsub-go.git
- Change the current working directory to the location of cloned directory.
cd redis-pubsub-go
- Run the following command to run all the services in docker container.
make run
- Run the following command to verify docker container is up and running.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a62b3a1a2205 redis-pubsub-go_publisher "./publisher" 21 minutes ago Up 1 second 0.0.0.0:9001->9001/tcp, :::9001->9001/tcp go-publisher
13a50aa092ac redis-pubsub-go_subscriber "./subscriber" 21 minutes ago Up 1 second go-subscriber
4a72e095f7b7 redis:latest "docker-entrypoint.s…" 21 minutes ago Up 2 seconds 0.0.0.0:6380->6379/tcp, :::6380->6379/tcp redis-pubsub
-
Open http://localhost:9001/swagger to send HTTP request using Swagger.
-
Run 'docker logs' on publisher, and subscriber to verify the message goes through redis and received on subsriber.
$ docker logs -f go-publisher
[GIN] 2021/11/17 - 17:29:34 | 200 | 358.299µs | 172.30.0.1 | POST "/publish"
$ docker logs -f go-subscriber
Received message: publisher.test, Data: "test"