49 lines
2.1 KiB
Markdown

# redis-queueing-sample
This repo aims to show how to communicate between two `services` using **Redis** as a message broker with [pub/sub channels](https://redis.io/docs/interact/pubsub/).
## How it works ?
```ascii
┌────────────┐
│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
```bash
make run
```
* Publish messages with the client
```bash
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 }
```