Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/damiancipolat/redis_pubsub_node
A complete example of event sourcing using redis pub/sub features with docker and nodejs + Typescript. In this situation we will create a SMS send distributed service.
https://github.com/damiancipolat/redis_pubsub_node
docker nodejs pubsub redis typescript
Last synced: about 14 hours ago
JSON representation
A complete example of event sourcing using redis pub/sub features with docker and nodejs + Typescript. In this situation we will create a SMS send distributed service.
- Host: GitHub
- URL: https://github.com/damiancipolat/redis_pubsub_node
- Owner: damiancipolat
- Created: 2020-04-26T17:09:35.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T04:28:02.000Z (almost 2 years ago)
- Last Synced: 2023-03-11T13:57:04.967Z (almost 2 years ago)
- Topics: docker, nodejs, pubsub, redis, typescript
- Language: TypeScript
- Size: 171 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SMS distributed services using redis PUB/SUB
An example of event sourcing using redis pub/sub features with docker and nodejs + Typescript. In this situation we will create a SMS send distributed service.## Stack:
Our stack will be:
- Node.js v12.0
- Express
- Docker + docker-compose
- TypeScript
- redis native client.
- redis tools.
- Mocks: mocky.io to simulate sms provider integration in a real example we can use aws/sns to send real sms or twilio.## Architecture:
There are two differents blocks.
- **Api rest**: Receive sms message send request and pubslish into the redis queue.
- **Workers**: Differents instances of a same nodejs docker image running in parralel, in this part we are working with mocked rest services rest services.### Pub - sub design:
All the server and workers run into a docker container, in the workers we user docker-compouse in scale mode.In this diagram, we are focusing the events architecture to create a async flow using events, I'm using the pub/sub **channels** as event queue.
### Channels:
- **SMS**: Used to publish a sms to be sent.
- **SMS_OK**: Is published when the sms was sent succefull.
- **SMS_FAIL**: Is published when the provider fail sending the sms, we can use this to make retries.### Events diagram:
## Environment:
To run the projec follow the next commands.```sh
#To run, using a scaling group as a daemon.
docker-compose up --scale workers=3 -d
```
- Api server: **port 8000**.
- Redir: **port 6379**.
- Workers: **port range 8000-9000**.## Request:
### **Send a SMS**:
```sh
curl --location --request POST 'http://127.0.0.1:8000/sms' \
--header 'Content-Type: application/json' \
--data-raw '{
"number":"+541166587382",
"text":"hello damian"
}'
```Reponse, the response have this format is an asyncronic process, so you have to make polling to detected when success.
```json
{
"uuid": "sms-1588048730269",
"number": "+541166587382",
"text": "hello damian"
}
```### **Get sms send status by uuid**:
```sh
curl --location --request GET 'http://127.0.0.1:8000/key/{uuid}'#Example:
curl --location --request GET 'http://127.0.0.1:8000/key/sms-1588048730269'
```