121 lines
2.9 KiB
Markdown
121 lines
2.9 KiB
Markdown
# Отчет по лабораторной работе №4
|
||
|
||
Выполнил студентка гр. ИСЭбд-41 Юденичева Дарья
|
||
|
||
## Tutorial
|
||
|
||
Установила rabbitMQ server, erlang и зашла в брокер под гостем по http://localhost:15672/#/
|
||
|
||
![](scrin/111.png)
|
||
|
||
Туториал-1:
|
||
|
||
![](scrin/222.png)
|
||
|
||
![](scrin/333.png)
|
||
|
||
Туториал 2:
|
||
|
||
![](scrin/444.png)
|
||
|
||
![](scrin/555.png)
|
||
|
||
Туториал 3:
|
||
|
||
![](scrin/666.png)
|
||
|
||
## Разработка демонстрационных приложений
|
||
|
||
Предметная область: Расходные договора и договора на платное обучение.
|
||
Разработа три приложения согласно предметной области.
|
||
|
||
1. Publisher
|
||
|
||
```py
|
||
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()
|
||
```
|
||
|
||
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:
|
||
|
||
![](scrin/777.png)
|
||
|
||
![](scrin/888.png)
|
||
|
||
Результат отработки Consumer_2:
|
||
|
||
![](scrin/999.png)
|
||
|
||
![](scrin/1000.png)
|
||
|
||
![](scrin/11.png)
|
||
|