diff --git a/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/.gitignore b/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/.name b/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/.name new file mode 100644 index 0000000..9edcde9 --- /dev/null +++ b/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/.name @@ -0,0 +1 @@ +receive.py \ No newline at end of file diff --git a/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/inspectionProfiles/profiles_settings.xml b/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/misc.xml b/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/misc.xml new file mode 100644 index 0000000..f715fb8 --- /dev/null +++ b/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/modules.xml b/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/modules.xml new file mode 100644 index 0000000..9b2ca55 --- /dev/null +++ b/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/python4Lab.iml b/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/python4Lab.iml new file mode 100644 index 0000000..74d515a --- /dev/null +++ b/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/python4Lab.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/vcs.xml b/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/vcs.xml new file mode 100644 index 0000000..4fce1d8 --- /dev/null +++ b/tasks/zinoveva-ad/lab_4/4Lab_python/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/tasks/zinoveva-ad/lab_4/4Lab_python/Python.gitignore b/tasks/zinoveva-ad/lab_4/4Lab_python/Python.gitignore new file mode 100644 index 0000000..68bc17f --- /dev/null +++ b/tasks/zinoveva-ad/lab_4/4Lab_python/Python.gitignore @@ -0,0 +1,160 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ diff --git a/tasks/zinoveva-ad/lab_4/4Lab_python/main_task/Consumer_1.py b/tasks/zinoveva-ad/lab_4/4Lab_python/main_task/Consumer_1.py new file mode 100644 index 0000000..ba5e8c8 --- /dev/null +++ b/tasks/zinoveva-ad/lab_4/4Lab_python/main_task/Consumer_1.py @@ -0,0 +1,20 @@ +import pika +import time + +def process_message(ch, method, properties, body): + print(f"Получено сообщение: {body}") + time.sleep(3) + print("Сообщение успешно обработано") + +connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) +channel = connection.channel() + +result = channel.queue_declare(queue='', exclusive=True) +queue_name = result.method.queue + +channel.queue_bind(exchange='Agreements', queue=queue_name) + +channel.basic_consume(queue=queue_name, on_message_callback=process_message, auto_ack=True) + +print('Ожидание сообщений...') +channel.start_consuming() \ No newline at end of file diff --git a/tasks/zinoveva-ad/lab_4/4Lab_python/main_task/Consumer_2.py b/tasks/zinoveva-ad/lab_4/4Lab_python/main_task/Consumer_2.py new file mode 100644 index 0000000..cc24bb1 --- /dev/null +++ b/tasks/zinoveva-ad/lab_4/4Lab_python/main_task/Consumer_2.py @@ -0,0 +1,19 @@ +import pika + + +def process_message(ch, method, properties, body): + print(f"Получено сообщение: {body}") + print("Сообщение успешно обработано") + +connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) +channel = connection.channel() + +result = channel.queue_declare(queue='', exclusive=True) +queue_name = result.method.queue + +channel.queue_bind(exchange='Agreements', queue=queue_name) + +channel.basic_consume(queue=queue_name, on_message_callback=process_message, auto_ack=True) + +print('Ожидание сообщений...') +channel.start_consuming() \ No newline at end of file diff --git a/tasks/zinoveva-ad/lab_4/4Lab_python/main_task/Publisher.py b/tasks/zinoveva-ad/lab_4/4Lab_python/main_task/Publisher.py new file mode 100644 index 0000000..7bb873c --- /dev/null +++ b/tasks/zinoveva-ad/lab_4/4Lab_python/main_task/Publisher.py @@ -0,0 +1,19 @@ +import pika +import time +import random + +collection = ["Application for general business expenses", "The contract is completed", "Enrollment order completed", "Student enrolled"] + +connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) +channel = connection.channel() + +channel.exchange_declare(exchange='Agreements', exchange_type='fanout') + +while True: + message = f"Message: {random.choice(collection)}" + + channel.basic_publish(exchange='Agreements', routing_key='', body=message) + + time.sleep(1) + +connection.close() \ No newline at end of file diff --git a/tasks/zinoveva-ad/lab_4/4Lab_python/tutorial_1/receive.py b/tasks/zinoveva-ad/lab_4/4Lab_python/tutorial_1/receive.py new file mode 100644 index 0000000..1c485bb --- /dev/null +++ b/tasks/zinoveva-ad/lab_4/4Lab_python/tutorial_1/receive.py @@ -0,0 +1,25 @@ +import pika, sys, os + +def main(): + connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) + channel = connection.channel() + + channel.queue_declare(queue='Logs') + + def callback(ch, method, properties, body): + print(f" [x] Получено сообщение: {body}") + + channel.basic_consume(queue='Logs', on_message_callback=callback, auto_ack=True) + + print(' [*] Ожидание сообщений. Для завершения CTRL+C') + channel.start_consuming() + +if __name__ == '__main__': + try: + main() + except KeyboardInterrupt: + print('Произошла ошибка') + try: + sys.exit(0) + except SystemExit: + os._exit(0) \ No newline at end of file diff --git a/tasks/zinoveva-ad/lab_4/4Lab_python/tutorial_1/send.py b/tasks/zinoveva-ad/lab_4/4Lab_python/tutorial_1/send.py new file mode 100644 index 0000000..80da5c2 --- /dev/null +++ b/tasks/zinoveva-ad/lab_4/4Lab_python/tutorial_1/send.py @@ -0,0 +1,11 @@ +import pika + +connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) +channel = connection.channel() + +channel.queue_declare(queue='sentimental_anna') + +channel.basic_publish(exchange='',routing_key='sentimental_anna',body='Hello, I have a cat, Busia, and a dog, Bonya!') +print(" [x] Отправлено сообщение") + +connection.close() \ No newline at end of file diff --git a/tasks/zinoveva-ad/lab_4/4Lab_python/tutorial_2/new_task.py b/tasks/zinoveva-ad/lab_4/4Lab_python/tutorial_2/new_task.py new file mode 100644 index 0000000..bd841cb --- /dev/null +++ b/tasks/zinoveva-ad/lab_4/4Lab_python/tutorial_2/new_task.py @@ -0,0 +1,13 @@ +import pika +import sys + +connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) +channel = connection.channel() + +channel.queue_declare(queue='sentimental_anna2', durable=True) + +message = ' '.join(sys.argv[1:]) or "Hello I have a cat, Busia, and a dog, Bonya!" +channel.basic_publish(exchange='', routing_key='sentimental_anna2', body=message, properties=pika.BasicProperties( + delivery_mode=pika.spec.PERSISTENT_DELIVERY_MODE)) +print(f" [x] Отправлено {message}") +connection.close() \ No newline at end of file diff --git a/tasks/zinoveva-ad/lab_4/4Lab_python/tutorial_2/worker.py b/tasks/zinoveva-ad/lab_4/4Lab_python/tutorial_2/worker.py new file mode 100644 index 0000000..9b09dfc --- /dev/null +++ b/tasks/zinoveva-ad/lab_4/4Lab_python/tutorial_2/worker.py @@ -0,0 +1,19 @@ +import pika +import time + +connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) +channel = connection.channel() + +channel.queue_declare(queue='sentimental_anna2', durable=True) +print(' [*] Ожидание сообщений. Для завершения CTRL+C') + +def callback(ch, method, properties, body): + print(f" [x] Получено сообщение: {body.decode()}") + time.sleep(body.count(b'.')) + print(" [x] Выполнено") + ch.basic_ack(delivery_tag=method.delivery_tag) + +channel.basic_qos(prefetch_count=1) +channel.basic_consume(queue='sentimental_anna2', on_message_callback=callback) + +channel.start_consuming() \ No newline at end of file diff --git a/tasks/zinoveva-ad/lab_4/4Lab_python/tutorial_3/emit_log.py b/tasks/zinoveva-ad/lab_4/4Lab_python/tutorial_3/emit_log.py new file mode 100644 index 0000000..532dd1a --- /dev/null +++ b/tasks/zinoveva-ad/lab_4/4Lab_python/tutorial_3/emit_log.py @@ -0,0 +1,12 @@ +import pika +import sys + +connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) +channel = connection.channel() + +channel.exchange_declare(exchange='Logs', exchange_type='fanout') + +message = ' '.join(sys.argv[1:]) or "Info: Hello I have a cat, Busia, and a dog, Bonya!" +channel.basic_publish(exchange='Logs', routing_key='', body=message) +print(f" [x] Отправлено сообщение: {message}") +connection.close() \ No newline at end of file diff --git a/tasks/zinoveva-ad/lab_4/4Lab_python/tutorial_3/receive_logs.py b/tasks/zinoveva-ad/lab_4/4Lab_python/tutorial_3/receive_logs.py new file mode 100644 index 0000000..c3e05ed --- /dev/null +++ b/tasks/zinoveva-ad/lab_4/4Lab_python/tutorial_3/receive_logs.py @@ -0,0 +1,21 @@ +import pika + +connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) +channel = connection.channel() + +channel.exchange_declare(exchange='Logs', exchange_type='fanout') + +result = channel.queue_declare(queue='', exclusive=True) +queue_name = result.method.queue + +channel.queue_bind(exchange='Logs', queue=queue_name) + +print(' [*] Ожидание сообщений. Для завершения CTRL+C') + +def callback(ch, method, properties, body): + print(f" [x] {body}") + +channel.basic_consume( + queue=queue_name, on_message_callback=callback, auto_ack=True) + +channel.start_consuming() \ No newline at end of file diff --git a/tasks/zinoveva-ad/lab_4/README.md b/tasks/zinoveva-ad/lab_4/README.md new file mode 100644 index 0000000..a79e656 --- /dev/null +++ b/tasks/zinoveva-ad/lab_4/README.md @@ -0,0 +1,118 @@ +# Отчет по лабораторной работе №4 + +Выполнила студентка гр. ИСЭбд-41 Зиновьева А. Д. + +## Прохождение tutorial + +Установила rabbitMQ server, erlang и зашла в брокер под гостем по http://localhost:15672/#/ +![](pic/Screenshot_7.jpg) + +Туториал 1: + +![](pic/Screenshot_1.jpg) +![](pic/Screenshot_2.jpg) +![](pic/Screenshot_3.jpg) + +Туториал 2: + +![](pic/Screenshot_4.jpg) +![](pic/Screenshot_5.jpg) +![](pic/Screenshot_8.jpg) + +Туториал 3: + +![](pic/Screenshot_9.jpg) +![](pic/Screenshot_10.jpg) +![](pic/Screenshot_11.jpg) + +## Разработка демонстрационных приложений + +Предметная область: Дополнительный соглашения и договоры на проживание. +Разработаны три приложения, согласно предметной области. + +1. Publisher + +```py +import pika +import time +import random + +collection = ["Application for accommodation in a dormitory", "Rector's order", "Conclusion of an agreement", "Check-into a dormitory"] + +connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) +channel = connection.channel() + +channel.exchange_declare(exchange='Agreements', exchange_type='fanout') + +while True: + message = f"Message: {random.choice(collection)}" + + channel.basic_publish(exchange='Agreements', routing_key='', body=message) + + time.sleep(1) + +connection.close() +``` + +2. Consumer 1. + +```py +import pika +import time + +def process_message(ch, method, properties, body): + print(f"Получено сообщение: {body}") + time.sleep(3) + print("Сообщение успешно обработано") + +connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) +channel = connection.channel() + +result = channel.queue_declare(queue='', exclusive=True) +queue_name = result.method.queue + +channel.queue_bind(exchange='Agreements', queue=queue_name) + +channel.basic_consume(queue=queue_name, on_message_callback=process_message, auto_ack=True) + +print('Ожидание сообщений...') +channel.start_consuming() +``` + +3. Consumer 2. + +```py +import pika + + +def process_message(ch, method, properties, body): + print(f"Получено сообщение: {body}") + print("Сообщение успешно обработано") + +connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) +channel = connection.channel() + +result = channel.queue_declare(queue='', exclusive=True) +queue_name = result.method.queue + +channel.queue_bind(exchange='Agreements', queue=queue_name) + +channel.basic_consume(queue=queue_name, on_message_callback=process_message, auto_ack=True) + +print('Ожидание сообщений...') +channel.start_consuming() +``` + +## Результаты выполнения лабораторной работы + +Результат отработки Consumer_1: + +![](pic/Screenshot_12.jpg) +![](pic/Screenshot_13.jpg) + +Результат отработки Consumer_2: + +![](pic/Screenshot_14.jpg) +![](pic/Screenshot_15.jpg) + +Вывод: Consumer_2 нагружает меньше памяти, чем Consumer_1 и принимает сообщения гораздо быстрее, тем самым не позволяя очереди накапливать огромное количество сообщений. \ No newline at end of file diff --git a/tasks/zinoveva-ad/lab_4/pic/Screenshot_1.jpg b/tasks/zinoveva-ad/lab_4/pic/Screenshot_1.jpg new file mode 100644 index 0000000..ad6ebba Binary files /dev/null and b/tasks/zinoveva-ad/lab_4/pic/Screenshot_1.jpg differ diff --git a/tasks/zinoveva-ad/lab_4/pic/Screenshot_10.jpg b/tasks/zinoveva-ad/lab_4/pic/Screenshot_10.jpg new file mode 100644 index 0000000..b8484ef Binary files /dev/null and b/tasks/zinoveva-ad/lab_4/pic/Screenshot_10.jpg differ diff --git a/tasks/zinoveva-ad/lab_4/pic/Screenshot_11.jpg b/tasks/zinoveva-ad/lab_4/pic/Screenshot_11.jpg new file mode 100644 index 0000000..afbeba3 Binary files /dev/null and b/tasks/zinoveva-ad/lab_4/pic/Screenshot_11.jpg differ diff --git a/tasks/zinoveva-ad/lab_4/pic/Screenshot_12.jpg b/tasks/zinoveva-ad/lab_4/pic/Screenshot_12.jpg new file mode 100644 index 0000000..72c9d30 Binary files /dev/null and b/tasks/zinoveva-ad/lab_4/pic/Screenshot_12.jpg differ diff --git a/tasks/zinoveva-ad/lab_4/pic/Screenshot_13.jpg b/tasks/zinoveva-ad/lab_4/pic/Screenshot_13.jpg new file mode 100644 index 0000000..ee44b55 Binary files /dev/null and b/tasks/zinoveva-ad/lab_4/pic/Screenshot_13.jpg differ diff --git a/tasks/zinoveva-ad/lab_4/pic/Screenshot_14.jpg b/tasks/zinoveva-ad/lab_4/pic/Screenshot_14.jpg new file mode 100644 index 0000000..2410bfa Binary files /dev/null and b/tasks/zinoveva-ad/lab_4/pic/Screenshot_14.jpg differ diff --git a/tasks/zinoveva-ad/lab_4/pic/Screenshot_15.jpg b/tasks/zinoveva-ad/lab_4/pic/Screenshot_15.jpg new file mode 100644 index 0000000..7b7d2e6 Binary files /dev/null and b/tasks/zinoveva-ad/lab_4/pic/Screenshot_15.jpg differ diff --git a/tasks/zinoveva-ad/lab_4/pic/Screenshot_2.jpg b/tasks/zinoveva-ad/lab_4/pic/Screenshot_2.jpg new file mode 100644 index 0000000..b6d26c0 Binary files /dev/null and b/tasks/zinoveva-ad/lab_4/pic/Screenshot_2.jpg differ diff --git a/tasks/zinoveva-ad/lab_4/pic/Screenshot_3.jpg b/tasks/zinoveva-ad/lab_4/pic/Screenshot_3.jpg new file mode 100644 index 0000000..e47b8f3 Binary files /dev/null and b/tasks/zinoveva-ad/lab_4/pic/Screenshot_3.jpg differ diff --git a/tasks/zinoveva-ad/lab_4/pic/Screenshot_4.jpg b/tasks/zinoveva-ad/lab_4/pic/Screenshot_4.jpg new file mode 100644 index 0000000..e8a2fd1 Binary files /dev/null and b/tasks/zinoveva-ad/lab_4/pic/Screenshot_4.jpg differ diff --git a/tasks/zinoveva-ad/lab_4/pic/Screenshot_5.jpg b/tasks/zinoveva-ad/lab_4/pic/Screenshot_5.jpg new file mode 100644 index 0000000..1f5ddc4 Binary files /dev/null and b/tasks/zinoveva-ad/lab_4/pic/Screenshot_5.jpg differ diff --git a/tasks/zinoveva-ad/lab_4/pic/Screenshot_6.jpg b/tasks/zinoveva-ad/lab_4/pic/Screenshot_6.jpg new file mode 100644 index 0000000..02f7e03 Binary files /dev/null and b/tasks/zinoveva-ad/lab_4/pic/Screenshot_6.jpg differ diff --git a/tasks/zinoveva-ad/lab_4/pic/Screenshot_7.jpg b/tasks/zinoveva-ad/lab_4/pic/Screenshot_7.jpg new file mode 100644 index 0000000..9f4de38 Binary files /dev/null and b/tasks/zinoveva-ad/lab_4/pic/Screenshot_7.jpg differ diff --git a/tasks/zinoveva-ad/lab_4/pic/Screenshot_8.jpg b/tasks/zinoveva-ad/lab_4/pic/Screenshot_8.jpg new file mode 100644 index 0000000..11a31dc Binary files /dev/null and b/tasks/zinoveva-ad/lab_4/pic/Screenshot_8.jpg differ diff --git a/tasks/zinoveva-ad/lab_4/pic/Screenshot_9.jpg b/tasks/zinoveva-ad/lab_4/pic/Screenshot_9.jpg new file mode 100644 index 0000000..8280dbb Binary files /dev/null and b/tasks/zinoveva-ad/lab_4/pic/Screenshot_9.jpg differ