Compare commits
1 Commits
melnikov-k
...
melnikov-k
| Author | SHA1 | Date | |
|---|---|---|---|
| e94714ed8f |
@@ -1,149 +0,0 @@
|
|||||||
# Отчёт по лабораторной работе №1
|
|
||||||
|
|
||||||
Выполнил: студент гр. ИСЭбд-41, Мельников К.Ю.
|
|
||||||
|
|
||||||
## Разворачивание сервиса Gitea
|
|
||||||
|
|
||||||
Содержимое файла `docker-compose.yml` в папке Gitea:
|
|
||||||
```yaml
|
|
||||||
version: "3"
|
|
||||||
|
|
||||||
networks:
|
|
||||||
gitea:
|
|
||||||
external: false
|
|
||||||
# Контейнер Gitea
|
|
||||||
services: # Описание служб
|
|
||||||
server:
|
|
||||||
image: gitea/gitea:1.20.4 # Образ gitea
|
|
||||||
container_name: gitea # Наименование контейнера
|
|
||||||
environment: # Наши параметры
|
|
||||||
- USER_UID=1000
|
|
||||||
- USER_GID=1000
|
|
||||||
- GITEA__database__DB_TYPE=mysql
|
|
||||||
- GITEA__database__HOST=db:3306
|
|
||||||
- GITEA__database__NAME=gitea
|
|
||||||
- GITEA__database__USER=gitea
|
|
||||||
- GITEA__database__PASSWD=gitea
|
|
||||||
restart: always
|
|
||||||
networks: # Параметры сети
|
|
||||||
- gitea
|
|
||||||
volumes: # Каталоги для хранения данных контейнера
|
|
||||||
- ./gitea:/data
|
|
||||||
- /etc/timezone:/etc/timezone:ro
|
|
||||||
- /etc/localtime:/etc/localtime:ro
|
|
||||||
ports: # Порт локальный и внутри сети
|
|
||||||
- "3000:3000"
|
|
||||||
- "222:22"
|
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
# База данных
|
|
||||||
db:
|
|
||||||
image: mysql:8 # Образ БД и версия
|
|
||||||
restart: always # Параметр перезапуска
|
|
||||||
environment: # Подключаем каталог с базой данных
|
|
||||||
- MYSQL_ROOT_PASSWORD=gitea
|
|
||||||
- MYSQL_USER=gitea
|
|
||||||
- MYSQL_PASSWORD=gitea
|
|
||||||
- MYSQL_DATABASE=gitea
|
|
||||||
networks: # Параметры сети
|
|
||||||
- gitea
|
|
||||||
volumes: # Том для хранения данных БД
|
|
||||||
- ./mysql:/var/lib/mysql
|
|
||||||
```
|
|
||||||
Далее в командной строке разворачиваем сервис командой `docker-compose up -d`:
|
|
||||||

|
|
||||||
|
|
||||||
Открываем Docker Desktop и проверяем, что контейнер сервера БД и Gitea созданы и запущены:
|
|
||||||

|
|
||||||
|
|
||||||
Переходим на http://localhost:222:
|
|
||||||

|
|
||||||
|
|
||||||
Регистрируемся и автоматически входим в учетную запись:
|
|
||||||

|
|
||||||

|
|
||||||
|
|
||||||
## Разворачивание сервиса Wordpress
|
|
||||||
|
|
||||||
Также в файл `docker-compose.yml` в папке Wordpress прописываем следующий код:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
version: '3.1'
|
|
||||||
|
|
||||||
services:
|
|
||||||
# Контейнер Wordpress
|
|
||||||
wordpress:
|
|
||||||
image: wordpress # Образ
|
|
||||||
restart: always # Параметр перезапуска
|
|
||||||
ports: # На каком порте запускаем
|
|
||||||
- 7071:80
|
|
||||||
environment: # Настройки БД WordPress для подключения
|
|
||||||
WORDPRESS_DB_HOST: database # Имя хоста БД MySQL
|
|
||||||
WORDPRESS_DB_USER: user # Имя пользователя БД
|
|
||||||
WORDPRESS_DB_PASSWORD: password # Пароль пользователя БД
|
|
||||||
WORDPRESS_DB_NAME: name_database # Имя БД
|
|
||||||
volumes: # Каталог хранения файлов WordPress
|
|
||||||
- wordpress:/var/www/html
|
|
||||||
# Контейнер MySQL
|
|
||||||
database:
|
|
||||||
image: mysql:5.7 # Образ и его версия
|
|
||||||
restart: always # Параметр перезапуска
|
|
||||||
environment: # Настройки БД для подключения
|
|
||||||
MYSQL_DATABASE: name_database
|
|
||||||
MYSQL_USER: user
|
|
||||||
MYSQL_PASSWORD: password
|
|
||||||
MYSQL_RANDOM_ROOT_PASSWORD: '12345'
|
|
||||||
volumes: # Каталог хранения данных БД
|
|
||||||
- database:/var/lib/mysql
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
wordpress:
|
|
||||||
database:
|
|
||||||
```
|
|
||||||
Далее в командной строке разворачиваем сервис командой `docker-compose up -d`:
|
|
||||||

|
|
||||||
|
|
||||||
Открываем Docker Desktop и проверяем, что контейнер сервера БД и Wordpress созданы и запущены
|
|
||||||
|
|
||||||
Устанавливаем Wordpress и проверяем, что все работает:
|
|
||||||

|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Разворачивание сервиса Redmine
|
|
||||||
|
|
||||||
Также в файл `docker-compose.yml` в папке Redmine прописываем код:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
version: '3.1'
|
|
||||||
|
|
||||||
services:
|
|
||||||
# Контейнер Redmine
|
|
||||||
redmine:
|
|
||||||
image: redmine # Образ контейнера
|
|
||||||
restart: always
|
|
||||||
ports: # На какой порт запускать
|
|
||||||
- 8080:3000
|
|
||||||
environment:
|
|
||||||
REDMINE_DB_MYSQL: db
|
|
||||||
REDMINE_DB_PASSWORD: example
|
|
||||||
REDMINE_SECRET_KEY_BASE: supersecretkey
|
|
||||||
# Контейнер БД MySQL
|
|
||||||
db:
|
|
||||||
image: mysql:5.7 # Образ БД и ее версия
|
|
||||||
restart: always
|
|
||||||
environment: # Название и пароль админа БД
|
|
||||||
MYSQL_ROOT_PASSWORD: example
|
|
||||||
MYSQL_DATABASE: redmine
|
|
||||||
```
|
|
||||||
Далее в командной строке разворачиваем сервис командой `docker-compose up -d`:
|
|
||||||
|
|
||||||
Открываем Docker Desktop и проверяем, что контейнер сервера БД и Redmine созданы и запущены:
|
|
||||||

|
|
||||||
|
|
||||||
Переходим на http://localhost:8080:
|
|
||||||

|
|
||||||
|
|
||||||
Регистрируемся и проверяем, что все работает:
|
|
||||||
|
Before Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 95 KiB |
|
Before Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 173 KiB |
|
Before Width: | Height: | Size: 170 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 198 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 47 KiB |
3
tasks/melnikov-ky/lab_4/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
1
tasks/melnikov-ky/lab_4/.idea/.name
generated
Normal file
@@ -0,0 +1 @@
|
|||||||
|
receive.py
|
||||||
6
tasks/melnikov-ky/lab_4/.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
7
tasks/melnikov-ky/lab_4/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.12 (python4Lab)" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (python4Lab)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
8
tasks/melnikov-ky/lab_4/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/python4Lab.iml" filepath="$PROJECT_DIR$/.idea/python4Lab.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
10
tasks/melnikov-ky/lab_4/.idea/python4Lab.iml
generated
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
6
tasks/melnikov-ky/lab_4/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
20
tasks/melnikov-ky/lab_4/MainTask/Consumer_1.py
Normal file
@@ -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()
|
||||||
19
tasks/melnikov-ky/lab_4/MainTask/Consumer_2.py
Normal file
@@ -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()
|
||||||
19
tasks/melnikov-ky/lab_4/MainTask/Publisher.py
Normal file
@@ -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()
|
||||||
160
tasks/melnikov-ky/lab_4/Python.gitignore
Normal file
@@ -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/
|
||||||
116
tasks/melnikov-ky/lab_4/README.md
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
# Отчет по лабораторной работе №4
|
||||||
|
|
||||||
|
Выполнил студент гр. ИСЭбд-41 Мельников К.Ю.
|
||||||
|
|
||||||
|
## Прохождение tutorial
|
||||||
|
|
||||||
|
Установил rabbitMQ server, erlang и зашел в брокер под гостем по http://localhost:15672/#/
|
||||||
|
|
||||||
|
Туториал 1:
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
Туториал 2:
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
Туториал 3:
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
## Разработка демонстрационных приложений
|
||||||
|
|
||||||
|
Предметная область: Дополенительные соглашения и договора на заселение в отель Туристического агентства.
|
||||||
|
Разработа три приложения согласно предметной области.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Результат отработки Consumer_2:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Вывод: Consumer_2 нагружает меньше памяти, чем Consumer_1 и принимает сообщения гораздо быстрее, тем самым не позволяя очереди накапливать огромное количество сообщений.
|
||||||
25
tasks/melnikov-ky/lab_4/Tut1/receive.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import pika, sys, os
|
||||||
|
|
||||||
|
def main():
|
||||||
|
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
|
||||||
|
channel = connection.channel()
|
||||||
|
|
||||||
|
channel.queue_declare(queue='MelnikovLogs')
|
||||||
|
|
||||||
|
def callback(ch, method, properties, body):
|
||||||
|
print(f" [x] Получено сообщение: {body}")
|
||||||
|
|
||||||
|
channel.basic_consume(queue='MelnikovLogs', 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)
|
||||||
11
tasks/melnikov-ky/lab_4/Tut1/send.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import pika
|
||||||
|
|
||||||
|
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
|
||||||
|
channel = connection.channel()
|
||||||
|
|
||||||
|
channel.queue_declare(queue='melnikov')
|
||||||
|
|
||||||
|
channel.basic_publish(exchange='',routing_key='melnikov',body='Hello, my name is Kirill, i am from ISEbd-41!')
|
||||||
|
print(" [x] Отправлено сообщение")
|
||||||
|
|
||||||
|
connection.close()
|
||||||
13
tasks/melnikov-ky/lab_4/Tut2/new_task.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import pika
|
||||||
|
import sys
|
||||||
|
|
||||||
|
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
|
||||||
|
channel = connection.channel()
|
||||||
|
|
||||||
|
channel.queue_declare(queue='melnikov2', durable=True)
|
||||||
|
|
||||||
|
message = ' '.join(sys.argv[1:]) or "Hello, my name is Kirill, i am from ISEbd-41!"
|
||||||
|
channel.basic_publish(exchange='', routing_key='melnikov2', body=message, properties=pika.BasicProperties(
|
||||||
|
delivery_mode=pika.spec.PERSISTENT_DELIVERY_MODE))
|
||||||
|
print(f" [x] Отправлено {message}")
|
||||||
|
connection.close()
|
||||||
19
tasks/melnikov-ky/lab_4/Tut2/worker.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import pika
|
||||||
|
import time
|
||||||
|
|
||||||
|
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
|
||||||
|
channel = connection.channel()
|
||||||
|
|
||||||
|
channel.queue_declare(queue='melnikov2', 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='melnikov2', on_message_callback=callback)
|
||||||
|
|
||||||
|
channel.start_consuming()
|
||||||
12
tasks/melnikov-ky/lab_4/Tut3/emit_log.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import pika
|
||||||
|
import sys
|
||||||
|
|
||||||
|
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
|
||||||
|
channel = connection.channel()
|
||||||
|
|
||||||
|
channel.exchange_declare(exchange='MelnikovLogs', exchange_type='fanout')
|
||||||
|
|
||||||
|
message = ' '.join(sys.argv[1:]) or "Info: Hello, my name is Kirill, i am from ISEbd-41!"
|
||||||
|
channel.basic_publish(exchange='MelnikovLogs', routing_key='', body=message)
|
||||||
|
print(f" [x] Отправлено сообщение: {message}")
|
||||||
|
connection.close()
|
||||||
21
tasks/melnikov-ky/lab_4/Tut3/receive_logs.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import pika
|
||||||
|
|
||||||
|
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
|
||||||
|
channel = connection.channel()
|
||||||
|
|
||||||
|
channel.exchange_declare(exchange='MelnikovLogs', exchange_type='fanout')
|
||||||
|
|
||||||
|
result = channel.queue_declare(queue='', exclusive=True)
|
||||||
|
queue_name = result.method.queue
|
||||||
|
|
||||||
|
channel.queue_bind(exchange='MelnikovLogs', 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()
|
||||||
BIN
tasks/melnikov-ky/lab_4/scrins/emitlog.png
Normal file
|
After Width: | Height: | Size: 27 KiB |
BIN
tasks/melnikov-ky/lab_4/scrins/maintask1.png
Normal file
|
After Width: | Height: | Size: 124 KiB |
BIN
tasks/melnikov-ky/lab_4/scrins/maintask2.png
Normal file
|
After Width: | Height: | Size: 126 KiB |
BIN
tasks/melnikov-ky/lab_4/scrins/maintask_dop.png
Normal file
|
After Width: | Height: | Size: 56 KiB |
BIN
tasks/melnikov-ky/lab_4/scrins/newtask.png
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
tasks/melnikov-ky/lab_4/scrins/receive.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
tasks/melnikov-ky/lab_4/scrins/receivelogs.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
tasks/melnikov-ky/lab_4/scrins/send.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
tasks/melnikov-ky/lab_4/scrins/tut1.png
Normal file
|
After Width: | Height: | Size: 128 KiB |
BIN
tasks/melnikov-ky/lab_4/scrins/tut2.png
Normal file
|
After Width: | Height: | Size: 121 KiB |
BIN
tasks/melnikov-ky/lab_4/scrins/tut3.png
Normal file
|
After Width: | Height: | Size: 127 KiB |
BIN
tasks/melnikov-ky/lab_4/scrins/worker.png
Normal file
|
After Width: | Height: | Size: 27 KiB |