Compare commits
No commits in common. "915b8bb68c44ab288e517f763a5eb8fc9d34f0da" and "8ad85b8049e4a050c316aa5f5a4cdbd55f780ee8" have entirely different histories.
915b8bb68c
...
8ad85b8049
@ -1,115 +0,0 @@
|
|||||||
# Отчет по лабораторной работе №4
|
|
||||||
|
|
||||||
Выполнила студентка гр. ИСЭбд-41 Островская С. Ф.
|
|
||||||
|
|
||||||
## Прохождение tutorial
|
|
||||||
|
|
||||||
Установила rabbitMQ server, erlang и зашла в брокер под гостем по http://localhost:15672/#/
|
|
||||||

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

|
|
||||||

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

|
|
||||||

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

|
|
||||||

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

|
|
||||||

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

|
|
||||||

|
|
||||||
|
|
||||||
Вывод: Consumer_2 нагружает меньше памяти, чем Consumer_1 и принимает сообщения гораздо быстрее, тем самым не позволяя очереди накапливать огромное количество сообщений.
|
|
3
tasks/ostrovskaya-sf/lab_4/lab_4_py/.idea/.gitignore
generated
vendored
@ -1,3 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
@ -1,6 +0,0 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<settings>
|
|
||||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
|
||||||
<version value="1.0" />
|
|
||||||
</settings>
|
|
||||||
</component>
|
|
@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="PYTHON_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
<content url="file://$MODULE_DIR$" />
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
|
|
||||||
</project>
|
|
@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/lab_4_py.iml" filepath="$PROJECT_DIR$/.idea/lab_4_py.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,20 +0,0 @@
|
|||||||
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()
|
|
@ -1,19 +0,0 @@
|
|||||||
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()
|
|
@ -1,19 +0,0 @@
|
|||||||
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()
|
|
@ -1,25 +0,0 @@
|
|||||||
import pika, sys, os
|
|
||||||
|
|
||||||
def main():
|
|
||||||
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
|
|
||||||
channel = connection.channel()
|
|
||||||
|
|
||||||
channel.queue_declare(queue='OstrovsofaLogs')
|
|
||||||
|
|
||||||
def callback(ch, method, properties, body):
|
|
||||||
print(f" [x] Получено сообщение: {body}")
|
|
||||||
|
|
||||||
channel.basic_consume(queue='OstrovsofaLogs', 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)
|
|
@ -1,11 +0,0 @@
|
|||||||
import pika
|
|
||||||
|
|
||||||
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
|
|
||||||
channel = connection.channel()
|
|
||||||
|
|
||||||
channel.queue_declare(queue='ostrovsofa')
|
|
||||||
|
|
||||||
channel.basic_publish(exchange='',routing_key='ostrovsofa',body='My cat"s name is Montik!')
|
|
||||||
print(" [x] Отправлено сообщение")
|
|
||||||
|
|
||||||
connection.close()
|
|
@ -1,13 +0,0 @@
|
|||||||
import pika
|
|
||||||
import sys
|
|
||||||
|
|
||||||
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
|
|
||||||
channel = connection.channel()
|
|
||||||
|
|
||||||
channel.queue_declare(queue='ostrovsofa2', durable=True)
|
|
||||||
|
|
||||||
message = ' '.join(sys.argv[1:]) or "My cat's name is Montik!"
|
|
||||||
channel.basic_publish(exchange='', routing_key='ostrovsofa2', body=message, properties=pika.BasicProperties(
|
|
||||||
delivery_mode=pika.spec.PERSISTENT_DELIVERY_MODE))
|
|
||||||
print(f" [x] Отправлено {message}")
|
|
||||||
connection.close()
|
|
@ -1,19 +0,0 @@
|
|||||||
import pika
|
|
||||||
import time
|
|
||||||
|
|
||||||
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
|
|
||||||
channel = connection.channel()
|
|
||||||
|
|
||||||
channel.queue_declare(queue='ostrovsofa2', 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='ostrovsofa2', on_message_callback=callback)
|
|
||||||
|
|
||||||
channel.start_consuming()
|
|
@ -1,12 +0,0 @@
|
|||||||
import pika
|
|
||||||
import sys
|
|
||||||
|
|
||||||
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
|
|
||||||
channel = connection.channel()
|
|
||||||
|
|
||||||
channel.exchange_declare(exchange='OstrovsofaLogs', exchange_type='fanout')
|
|
||||||
|
|
||||||
message = ' '.join(sys.argv[1:]) or "Info: My cat's name is Montik!"
|
|
||||||
channel.basic_publish(exchange='OstrovsofaLogs', routing_key='', body=message)
|
|
||||||
print(f" [x] Отправлено сообщение: {message}")
|
|
||||||
connection.close()
|
|
@ -1,21 +0,0 @@
|
|||||||
import pika
|
|
||||||
|
|
||||||
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
|
|
||||||
channel = connection.channel()
|
|
||||||
|
|
||||||
channel.exchange_declare(exchange='OstrovsofaLogs', exchange_type='fanout')
|
|
||||||
|
|
||||||
result = channel.queue_declare(queue='', exclusive=True)
|
|
||||||
queue_name = result.method.queue
|
|
||||||
|
|
||||||
channel.queue_bind(exchange='OstrovsofaLogs', 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()
|
|
Before Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 76 KiB |
Before Width: | Height: | Size: 132 KiB |
Before Width: | Height: | Size: 53 KiB |
Before Width: | Height: | Size: 87 KiB |
Before Width: | Height: | Size: 41 KiB |
Before Width: | Height: | Size: 124 KiB |
Before Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 127 KiB |
Before Width: | Height: | Size: 74 KiB |
Before Width: | Height: | Size: 130 KiB |