Introduction to PubSub or Event-driven architecture using Redis and FastAPI
-
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.
Follow the below steps to configure the environment.
- Install the poetry.
pip install poetry
- Initialize poetry shell.
poetry shell
- Install the dependencies.
poetry install
- 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.
To run the api, use the following command.
`sh run.sh`
- 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."
- 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.
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 !!!