bigchungusdata/rabbit/publisher.py

15 lines
577 B
Python

#!/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 + "\""
binstring = string.encode('UTF-8')
while True:
channel.basic_publish(exchange="test",routing_key="test",body=binstring)
except KeyboardInterrupt:
connection.close()