some things done

This commit is contained in:
2021-04-24 18:43:28 +02:00
commit 8c3bc4f217
7 changed files with 78 additions and 0 deletions

28
rabbit/consumer.py Normal file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env python3
from datetime import datetime
import pika
DATETIMES=[]
def callback(ch, method, properties, body):
DATETIMES.append(datetime.now())
try:
n = 10
credentials = pika.PlainCredentials("rabbit", "rabbit")
connection = pika.BlockingConnection(pika.ConnectionParameters(host="localhost", credentials=credentials, heartbeat=0, socket_timeout=5))
channel = connection.channel()
channel.exchange_declare(exchange="test",exchange_type='direct')
queue_declare_result = channel.queue_declare(queue='testqueue', exclusive=False)
queue_name = queue_declare_result.method.queue
channel.queue_bind(exchange="test",routing_key='test', queue=queue_name)
channel.basic_qos(prefetch_count=1)
channel.basic_consume(queue=queue_name, on_message_callback=callback, auto_ack=True)
channel.start_consuming()
except Exception:
connection.close()
print(DATETIMES)

10
rabbit/docker-compose.yml Normal file
View File

@ -0,0 +1,10 @@
version: "3"
services:
rabbitmq:
image: rabbitmq:3-management-alpine
environment:
RABBITMQ_DEFAULT_USER: rabbit
RABBITMQ_DEFAULT_PASS: rabbit
ports:
- 5672:5672
- 15672:15672

13
rabbit/publisher.py Normal file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env python3
import pika
try:
n = 10
credentials = pika.PlainCredentials("rabbit", "rabbit")
connection = pika.BlockingConnection(pika.ConnectionParameters(host="localhost", credentials=credentials, heartbeat=0, socket_timeout=5))
channel = connection.channel()
channel.exchange_declare(exchange="test",exchange_type='direct')
string = "\"" + "a" * n + "\""
while True:
channel.basic_publish(exchange="test",routing_key="test",body=string.encode('UTF-8'))
except Exception:
connection.close()