2.1 KiB
2.1 KiB
redis-queueing-sample
This repo aims to show how to communicate between two services using Redis as a message broker with pub/sub channels.
How it works ?
┌────────────┐
│server │
┌───────────────► │
│ │ │
│ │ │
┌────────────┐ ┌─────┴──────┐ │ │
│client │ │redis │ └────────────┘
│ │ │ │
│ ├───────► │
│ │ │ │
│ │ │:6379 │ ┌────────────┐
└────────────┘ └─────┬──────┘ │server │
│ │ │
│ │ │
│ │ │
└───────────────► │
└────────────┘
- A client publish a message to the Redis channel
- Servers subscribe to the channel and handle the message
Run
- Start Redis and the server
make run
- Publish messages with the client
make run-client
You should see the following server logs:
listening message...
Received data: Message { id: 1, action: Download }
Received data: Message { id: 1, action: Download }
Received data: Message { id: 1, action: Download }
Received data: Message { id: 1, action: Download }
Received data: Message { id: 1, action: Download }
Received data: Message { id: 1, action: Download }
Received data: Message { id: 1, action: Download }