Coder Social home page Coder Social logo

jxnxts / fastapi-celery-rabbitmq-application Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sumanentc/fastapi-celery-rabbitmq-application

0.0 0.0 0.0 663 KB

Sample FastAPI Application to demonstrate Async architecture with Celery, RabbitMQ and Flower

License: MIT License

Python 100.00%

fastapi-celery-rabbitmq-application's Introduction

Sample FastAPI Application to demonstrate Async architecture with Celery, RabbitMQ and Flower

alt text

Sample application utilizing FastAPI, Celery with RabbitMQ for task queue. RabbitMQ is also used as Celery backend and optional flower for monitoring the Celery tasks.

FastAPI

FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.

The key features are:

Fast: Very high performance, on par with NodeJS and Go (thanks to Starlette and Pydantic). One of the fastest Python frameworks available.

Fast to code: It allows for significant increases in development speed.

Easy: Designed to be easy to use and learn. Less time reading docs. Short: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs. Robust: Get production-ready code. With automatic interactive documentation. Standards-based: It’s based on the open standards for APIs, OpenAPI and JSON Schema.

Celery

Celery is a simple, flexible, and reliable distributed system to process vast amounts of messages, while providing operations with the tools required to maintain such a system. It’s a task queue with focus on real-time processing, while also supporting task scheduling. It also helps us to handle asynchronous tasks, which is vital for smooth user experiences. With this powerful combo of FastAPI and Celery, we will be able to do things like:

  • Run machine learning models
  • Send bulk emails
  • Process images or PDFs
  • Generate exports of user data
  • Perform backups

RabbitMQ

RabbitMQ is the most widely deployed open source message broker.

Flower

Flower is a real-time web application monitoring and administration tool for Celery.

Architecture

alt text

Setting up the VirtualEnv and install dependencies

Go inside the project folder and execute the below commands. We will use Pipenv to setup the VirtualEnv.

pipenv shell --python 3.9.2
pipenv install -r requirements.txt

Dependencies will be installed from the Pipfile. Python version 3.9.2 is used for this project.

Prerequisite

  1. Python 3.9.2
  2. Pipenv packaging tool
  3. RabbitMQ instance

Run the Application

python main.py

Start the Celery process, navigate to the project directory in a new terminal, activate the virtual environment, and then run:

pipenv shell --python 3.9.2
pipenv install -r requirements.txt
celery -A main.celery worker --loglevel=info -Q universities,university --concurrency=3

Optionally we can monitor the tasks submitted to Celery. To start the Flower process, Navigate to the project directory in a new terminal, activate the virtual environment, and then run:

pipenv shell --python 3.9.2
pipenv install -r requirements.txt
celery -A main.celery flower --port=5555

Once the Flower starts we cann see the submitted tasks at http://localhost:5555/tasks.

alt text

This will start the application on port 9000 and Celery process will listen to the Queue universities,university

Test the application

FastAPI also automatically generated fully interactive API documentation that we can use to interact with our API. We can visit http://127.0.0.1:9000/docs in our browser to see the interactive API documentation provided by Swagger UI:

alt text

The server will start at http://localhost:9000/docs.

Please check out the article for further details. Async Architecture with FastAPI, Celery, and RabbitMQ

References

fastapi-celery-rabbitmq-application's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.