PubSub Architecture using FastAPI and Redis
Introduction to PubSub or Event-driven architecture using Redis and FastAPI
Workflow
-
Publisher tries to connect to external API leveraging the power of asynchronous and parallel processing and fetches the response.
-
The response is then published on the REDIS CHANNEL.
-
This response/message is then further fetched by the subscriber by subscribing the REDIS CHANNEL.
Configuring the environment
Follow the below steps to configure the environment.
- Install the poetry.
pip install poetry
- Initialize poetry shell.
poetry shell
- Install the dependencies.
poetry install
Configuring the project
- To configure the url, host and port numbers, copy the '.env.example' file.
- Rename it to '.env'
- Change the values with your required host and port numbers.
Run the project
To run the api, use the following command.
`sh run.sh`
API Documentation
- For the API documentation, copy the three urls into three separate tabs in the browser.
- Append "/docs" to the end of each urls.
- Click on "Try it Out" and then hit "Execute."
Screenshots :
- Beer Details API
- Publisher API
- Subsriber API
Once you hit the execute button, you will be able to see the messages getting printed on the terminal.
NOTE :
Since this is just an introduction to the implementation of Redis as a message broker. Feel free to use this as a reference to expand your knowledge on the Event-Driven Architecture.
Happy Learning !!!