bigchungusdata/rabbit/publisher.py

15 lines
577 B
Python
Raw Normal View History

2021-04-24 18:43:28 +02:00
#!/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 + "\""
2021-04-24 19:01:26 +02:00
binstring = string.encode('UTF-8')
2021-04-24 18:43:28 +02:00
while True:
2021-04-24 19:01:26 +02:00
channel.basic_publish(exchange="test",routing_key="test",body=binstring)
2021-04-25 12:24:41 +02:00
except KeyboardInterrupt:
2021-04-24 18:43:28 +02:00
connection.close()