Skip to content

CLI app that demonstrates an example of working with RabbitMQ

Notifications You must be signed in to change notification settings

KsyushaKI/tasks-for-rabbitmq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tasks for RabbitMQ

CLI app that demonstrates an example of working with RabbitMQ

Maintainability

About

CLI app that demonstrates an example of working with RabbitMQ. Tasks for RabbitMQ include the following programs:

  • file_generation.py: every 5 seconds generates a file with an arbitrary name in the folder "data", the content of the file is equal to the file name (for example "1052.txt"). The program runs within 2 minutes;
  • publisher.py: every 15 seconds will send the current list of files in the "data" folder in json format to RabbitMq;
  • consumer.py: reads messages from RabbitMq. Messages are read as soon as the "publisher" sends them to RabbitMq. The received message is processed for 35 seconds (imitation of file processing), namely: the contents of the files are combined and a text file is created in the "result" folder. The filename is equal to the RabbitMq message ID. The original files are deleted.

Example:

>> consumer

 [*] Waiting for messages. To exit press CTRL+C
 [x] Received b'{"files": ["1052.txt", "6717.txt", "3336.txt", "3962.txt", "3248.txt", "4292.txt"], "message_id": 1}'
 [x] Done
 [x] Received b'{"files": ["9341.txt", "8918.txt", "7139.txt"], "message_id": 4}'
 [x] Done
 [x] Received b'{"files": ["1297.txt", "1425.txt", "5703.txt"], "message_id": 7}'
 [x] Done
 [x] Received b'{"files": [], "message_id": 10}'
 [x] Done
^CInterrupted

Built With


Installation

Prerequisites

Python

Before installing the package make sure you have Python version 3.8 or higher installed:

>> python --version
Python 3.8.0+

Poetry

The project uses the Poetry dependency manager. To install Poetry use its official instruction.

RabbitMQ

The project uses the RabbitMQ message broker. To install RabbitMQ use its official instruction.

Package

To use the package, you need to clone the repository to your computer. This is done using the git clone command. Clone the project:

>> git clone https://github.com/KsyushaKI/tasks-for-rabbitmq

Then you have to build the package and install it:

>> cd tasks-for-rabbitmq
>> make install
>> make build
>> make package-install

Usage

To start working with the installed program do the following:

  1. To start RabbitMQ server:
>> brew services start rabbitmq
  1. Open three terminal windows and in each of them run the command:
>> consumer
  1. In a new terminal window, run the command:
>> file_generation
  1. In a new terminal window, run the command:
>> publisher
  1. To stop running programs use the fillowing in each open window:
>> CTRL+C
  1. To stop RabbitMQ server:
>> brew services stop rabbitmq

Additionally

Dependencies

  • python = "^3.11"
  • pika = "^1.3.2"
  • interruptingcow = "^0.8"
  • rabbitmq = "^0.2.0"

Dev Dependencies

  • flake8 = "^6.0.0"

GitHub @KsyushaKI  ·  LinkedIn @Oksana Karshakevich

About

CLI app that demonstrates an example of working with RabbitMQ

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published