Giter Site home page Giter Site logo

mxaviersmp / producer-consumer-service Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 132 KB

A Producer and a Consumer service that will be connected through a Queue.

License: MIT License

Shell 2.62% Dockerfile 12.29% Makefile 11.49% Python 73.60%
rabbitmq fastapi queue pika aio-pika unit-testing integration-testing mypy flake8 pytest

producer-consumer-service's Introduction

consumer-producer-service

A Producer and a Consumer service that will be connected through a Queue

System Architecture

Producer

  • API exposed via HTTP
  • Receives data in JSON format
  • Puts the JSON it received in the queue

Build with FastAPI and aio_pika

Consumer

  • Listens to the queue
  • Appends the records to an output.txt file

Built with pika

Development

If using vscode, a devcontainer configuration for local development is available.

The app uses flake8 for code linting and mypy for type checking, and uses pytest to run unit and integration tests.

Usage

The Makefile contains the commands to run the app.

Use the env.example to configure the environment variables in .env.

After configuring the .env file, start the app by running make start-app. This will pull the images, build then start the containers.

After it is complete, access http://localhost:8000/docs to see the swagger documentation of the producer api. You can also check the logs by running make logs-app.

Use the endpoint /process to send a message to the queue. If it returns success, the message was put in the queue successfully. If the logs were opened, you will be able to see something like the following:

producer_1  | 2021-06-13 17:39:34.569 | INFO     | main.py:90 @process - Sent {'hello': 'world'} to queue default
...
consumer_1  | 2021-06-13 17:39:34.564 | INFO     | main.py:37 @callback -  [โœ“] Received b'{"hello": "world"}' on queue default

Now, check the file output.txt, in the same folder as the docker-compose.yml to see the message added to the end of the file.

producer-consumer-service's People

Contributors

mxaviersmp avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

cxliuneu

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.