113 lines
3.2 KiB
Markdown
113 lines
3.2 KiB
Markdown
# Отчет по лабораторной работе №4
|
|
Выполнила студентка группы ИСЭбд-41 Клементьева Жанна Андреевна
|
|
|
|
|
|
Порядок действий:
|
|
1. Установила rabbitMQ server, erlang
|
|
2. Зашла в брокер под гостем по http://localhost:15672/#/
|
|
|
|
Урок №1:
|
|
|
|

|
|

|
|
|
|
Урок №2:
|
|
|
|

|
|
|
|
Урок №3:
|
|
|
|

|
|
|
|
## Разработка демонстрационных приложений
|
|
Так как необходимо было выбрать предметную область, мой выбор остановился на:
|
|
Договора на платное внедрение системы менеджмента качества на предприятиях.
|
|
|
|
|
|
Далее было разработано три приложения:
|
|
|
|
1. Publisher
|
|
|
|
```py
|
|
import pika
|
|
import time
|
|
import random
|
|
|
|
collection = ["Application for the implementation of a quality management system", "The contract is completed", "Enrollment order completed", "System implemented"]
|
|
|
|
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_1 нагружает больше, чем Consumer_2. Также он принимает сообщения гораздо медленнее.
|