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.
>> 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
Before installing the package make sure you have Python version 3.8 or higher installed:
>> python --version
Python 3.8.0+
The project uses the Poetry dependency manager. To install Poetry use its official instruction.
The project uses the RabbitMQ message broker. To install RabbitMQ use its official instruction.
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
To start working with the installed program do the following:
- To start RabbitMQ server:
>> brew services start rabbitmq
- Open three terminal windows and in each of them run the command:
>> consumer
- In a new terminal window, run the command:
>> file_generation
- In a new terminal window, run the command:
>> publisher
- To stop running programs use the fillowing in each open window:
>> CTRL+C
- To stop RabbitMQ server:
>> brew services stop rabbitmq
- python = "^3.11"
- pika = "^1.3.2"
- interruptingcow = "^0.8"
- rabbitmq = "^0.2.0"
- flake8 = "^6.0.0"
GitHub @KsyushaKI · LinkedIn @Oksana Karshakevich