diff --git a/distributed-computing.sln b/distributed-computing.sln new file mode 100644 index 0000000..b1a0067 --- /dev/null +++ b/distributed-computing.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.002.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tasks", "tasks", "{2B6E26D7-A7B8-4D54-BBF4-015BA705E56A}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "moiseev-vv", "moiseev-vv", "{965B8A87-9BDC-4BCD-AFDB-3E44E4A74787}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lab_2", "lab_2", "{9A3A59F9-8935-453F-A787-C01D0050EEC3}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "worker-1", "tasks\moiseev-vv\lab_2\worker-1\worker-1.csproj", "{BEA0DAB8-B17C-45E3-9381-6B9AC6501137}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "worker-2", "tasks\moiseev-vv\lab_2\worker-2\worker-2.csproj", "{31367C2B-C332-48BF-A72F-B9C382EAF53B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BEA0DAB8-B17C-45E3-9381-6B9AC6501137}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BEA0DAB8-B17C-45E3-9381-6B9AC6501137}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BEA0DAB8-B17C-45E3-9381-6B9AC6501137}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BEA0DAB8-B17C-45E3-9381-6B9AC6501137}.Release|Any CPU.Build.0 = Release|Any CPU + {31367C2B-C332-48BF-A72F-B9C382EAF53B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {31367C2B-C332-48BF-A72F-B9C382EAF53B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {31367C2B-C332-48BF-A72F-B9C382EAF53B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {31367C2B-C332-48BF-A72F-B9C382EAF53B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {965B8A87-9BDC-4BCD-AFDB-3E44E4A74787} = {2B6E26D7-A7B8-4D54-BBF4-015BA705E56A} + {9A3A59F9-8935-453F-A787-C01D0050EEC3} = {965B8A87-9BDC-4BCD-AFDB-3E44E4A74787} + {BEA0DAB8-B17C-45E3-9381-6B9AC6501137} = {9A3A59F9-8935-453F-A787-C01D0050EEC3} + {31367C2B-C332-48BF-A72F-B9C382EAF53B} = {9A3A59F9-8935-453F-A787-C01D0050EEC3} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {158B89FF-64DF-43B9-8F23-E937532CE338} + EndGlobalSection +EndGlobal diff --git a/tasks/dunaev-oi/MainTask/Consumer_1.py b/tasks/dunaev-oi/MainTask/Consumer_1.py new file mode 100644 index 0000000..ba5e8c8 --- /dev/null +++ b/tasks/dunaev-oi/MainTask/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/dunaev-oi/MainTask/Consumer_2.py b/tasks/dunaev-oi/MainTask/Consumer_2.py new file mode 100644 index 0000000..cc24bb1 --- /dev/null +++ b/tasks/dunaev-oi/MainTask/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/dunaev-oi/MainTask/Publisher.py b/tasks/dunaev-oi/MainTask/Publisher.py new file mode 100644 index 0000000..83a6570 --- /dev/null +++ b/tasks/dunaev-oi/MainTask/Publisher.py @@ -0,0 +1,19 @@ +import pika +import time +import random + +collection = ["Application for Travel Agency", "Buying tickets", "Execution of the agreement", "Check-into a hotel"] + +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/dunaev-oi/Python.gitignore b/tasks/dunaev-oi/Python.gitignore new file mode 100644 index 0000000..68bc17f --- /dev/null +++ b/tasks/dunaev-oi/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/dunaev-oi/README.md b/tasks/dunaev-oi/README.md new file mode 100644 index 0000000..63d3844 --- /dev/null +++ b/tasks/dunaev-oi/README.md @@ -0,0 +1,116 @@ +# Отчет по лабораторной работе №4 + +Выполнил студент гр. ИСЭбд-41 Дунаев О.И. + +## Прохождение tutorial + +Установил rabbitMQ server, erlang и зашел в брокер под гостем по http://localhost:15672/#/ + +Туториал 1: + +![](scrins/tut1.png) +![](scrins/send.png) +![](scrins/receive.png) +Туториал 2: + +![](scrins/tut2.png) +![](scrins/newtask.png) +![](scrins/worker.png) + +Туториал 3: + +![](scrins/tut3.png) +![](scrins/emitlog.png) +![](scrins/receivelogs.png) + +## Разработка демонстрационных приложений + +Предметная область: Дополенительные соглашения и договора на заселение в отель Туристического агентства. +Разработа три приложения согласно предметной области. + +1. Publisher + +```py +import pika +import time +import random + +collection = ["Application for Travel Agency", "Buying tickets", "Execution of the agreement", "Check-into a hotel"] + +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: + +![](scrins/maintask1.png) + +Результат отработки Consumer_2: + +![](scrins/maintask2.png) + +![](scrins/maintask_dop.png) + +Вывод: Consumer_2 нагружает меньше памяти, чем Consumer_1 и принимает сообщения гораздо быстрее, тем самым не позволяя очереди накапливать огромное количество сообщений. \ No newline at end of file diff --git a/tasks/dunaev-oi/Tut1/receive.py b/tasks/dunaev-oi/Tut1/receive.py new file mode 100644 index 0000000..a827903 --- /dev/null +++ b/tasks/dunaev-oi/Tut1/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='DunaevLogs') + + def callback(ch, method, properties, body): + print(f" [x] Получено сообщение: {body}") + + channel.basic_consume(queue='DunaevLogs', 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/dunaev-oi/Tut1/send.py b/tasks/dunaev-oi/Tut1/send.py new file mode 100644 index 0000000..213815d --- /dev/null +++ b/tasks/dunaev-oi/Tut1/send.py @@ -0,0 +1,11 @@ +import pika + +connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) +channel = connection.channel() + +channel.queue_declare(queue='dunaev') + +channel.basic_publish(exchange='',routing_key='dunaev',body='Hello, my name is Oleg, i am from ISEbd-41!') +print(" [x] Отправлено сообщение") + +connection.close() \ No newline at end of file diff --git a/tasks/dunaev-oi/Tut2/new_task.py b/tasks/dunaev-oi/Tut2/new_task.py new file mode 100644 index 0000000..5666bf6 --- /dev/null +++ b/tasks/dunaev-oi/Tut2/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='dunaev2', durable=True) + +message = ' '.join(sys.argv[1:]) or "Hello, my name is Oleg, i am from ISEbd-41!" +channel.basic_publish(exchange='', routing_key='dunaev2', 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/dunaev-oi/Tut2/worker.py b/tasks/dunaev-oi/Tut2/worker.py new file mode 100644 index 0000000..a07d16b --- /dev/null +++ b/tasks/dunaev-oi/Tut2/worker.py @@ -0,0 +1,19 @@ +import pika +import time + +connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) +channel = connection.channel() + +channel.queue_declare(queue='dunaev2', durable=True) +print(' [*] Ожидание сообщений.') + +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='dunaev2', on_message_callback=callback) + +channel.start_consuming() \ No newline at end of file diff --git a/tasks/dunaev-oi/Tut3/emit_log.py b/tasks/dunaev-oi/Tut3/emit_log.py new file mode 100644 index 0000000..44be490 --- /dev/null +++ b/tasks/dunaev-oi/Tut3/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='DunaevLogs', exchange_type='fanout') + +message = ' '.join(sys.argv[1:]) or "Info: Hello, my name is Oleg, i am from ISEbd-41!" +channel.basic_publish(exchange='DunaevLogs', routing_key='', body=message) +print(f" [x] Отправлено сообщение: {message}") +connection.close() \ No newline at end of file diff --git a/tasks/dunaev-oi/Tut3/receive_logs.py b/tasks/dunaev-oi/Tut3/receive_logs.py new file mode 100644 index 0000000..d884058 --- /dev/null +++ b/tasks/dunaev-oi/Tut3/receive_logs.py @@ -0,0 +1,21 @@ +import pika + +connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) +channel = connection.channel() + +channel.exchange_declare(exchange='DunaevLogs', exchange_type='fanout') + +result = channel.queue_declare(queue='', exclusive=True) +queue_name = result.method.queue + +channel.queue_bind(exchange='DunaevLogs', 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/dunaev-oi/scrins/emitlog.png b/tasks/dunaev-oi/scrins/emitlog.png new file mode 100644 index 0000000..3cbbe67 Binary files /dev/null and b/tasks/dunaev-oi/scrins/emitlog.png differ diff --git a/tasks/dunaev-oi/scrins/maintask1.png b/tasks/dunaev-oi/scrins/maintask1.png new file mode 100644 index 0000000..582d0fc Binary files /dev/null and b/tasks/dunaev-oi/scrins/maintask1.png differ diff --git a/tasks/dunaev-oi/scrins/maintask2.png b/tasks/dunaev-oi/scrins/maintask2.png new file mode 100644 index 0000000..5f3409e Binary files /dev/null and b/tasks/dunaev-oi/scrins/maintask2.png differ diff --git a/tasks/dunaev-oi/scrins/maintask_dop.png b/tasks/dunaev-oi/scrins/maintask_dop.png new file mode 100644 index 0000000..d393697 Binary files /dev/null and b/tasks/dunaev-oi/scrins/maintask_dop.png differ diff --git a/tasks/dunaev-oi/scrins/newtask.png b/tasks/dunaev-oi/scrins/newtask.png new file mode 100644 index 0000000..90d6c62 Binary files /dev/null and b/tasks/dunaev-oi/scrins/newtask.png differ diff --git a/tasks/dunaev-oi/scrins/receive.png b/tasks/dunaev-oi/scrins/receive.png new file mode 100644 index 0000000..7fd1be9 Binary files /dev/null and b/tasks/dunaev-oi/scrins/receive.png differ diff --git a/tasks/dunaev-oi/scrins/receivelogs.png b/tasks/dunaev-oi/scrins/receivelogs.png new file mode 100644 index 0000000..9f573a8 Binary files /dev/null and b/tasks/dunaev-oi/scrins/receivelogs.png differ diff --git a/tasks/dunaev-oi/scrins/send.png b/tasks/dunaev-oi/scrins/send.png new file mode 100644 index 0000000..1f40933 Binary files /dev/null and b/tasks/dunaev-oi/scrins/send.png differ diff --git a/tasks/dunaev-oi/scrins/tut1.png b/tasks/dunaev-oi/scrins/tut1.png new file mode 100644 index 0000000..fd9973c Binary files /dev/null and b/tasks/dunaev-oi/scrins/tut1.png differ diff --git a/tasks/dunaev-oi/scrins/tut2.png b/tasks/dunaev-oi/scrins/tut2.png new file mode 100644 index 0000000..73a7c73 Binary files /dev/null and b/tasks/dunaev-oi/scrins/tut2.png differ diff --git a/tasks/dunaev-oi/scrins/tut3.png b/tasks/dunaev-oi/scrins/tut3.png new file mode 100644 index 0000000..ce85894 Binary files /dev/null and b/tasks/dunaev-oi/scrins/tut3.png differ diff --git a/tasks/dunaev-oi/scrins/worker.png b/tasks/dunaev-oi/scrins/worker.png new file mode 100644 index 0000000..f629ab5 Binary files /dev/null and b/tasks/dunaev-oi/scrins/worker.png differ