cleanup and kafka producer
This commit is contained in:
parent
8c3bc4f217
commit
8bab3d9116
@ -1 +1,15 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
from kafka import KafkaProducer
|
||||||
|
|
||||||
|
|
||||||
|
producer = KafkaProducer(bootstrap_servers='localhost:9092')
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
n = 10
|
||||||
|
string = "\"" + "a" * n + "\""
|
||||||
|
binstring = string.encode('UTF-8')
|
||||||
|
while True:
|
||||||
|
producer.send('test', binstring)
|
||||||
|
except Exception:
|
||||||
|
producer.close()
|
||||||
|
@ -12,7 +12,6 @@ def callback(ch, method, properties, body):
|
|||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
n = 10
|
|
||||||
credentials = pika.PlainCredentials("rabbit", "rabbit")
|
credentials = pika.PlainCredentials("rabbit", "rabbit")
|
||||||
connection = pika.BlockingConnection(pika.ConnectionParameters(host="localhost", credentials=credentials, heartbeat=0, socket_timeout=5))
|
connection = pika.BlockingConnection(pika.ConnectionParameters(host="localhost", credentials=credentials, heartbeat=0, socket_timeout=5))
|
||||||
channel = connection.channel()
|
channel = connection.channel()
|
||||||
|
@ -7,7 +7,8 @@ try:
|
|||||||
channel = connection.channel()
|
channel = connection.channel()
|
||||||
channel.exchange_declare(exchange="test",exchange_type='direct')
|
channel.exchange_declare(exchange="test",exchange_type='direct')
|
||||||
string = "\"" + "a" * n + "\""
|
string = "\"" + "a" * n + "\""
|
||||||
|
binstring = string.encode('UTF-8')
|
||||||
while True:
|
while True:
|
||||||
channel.basic_publish(exchange="test",routing_key="test",body=string.encode('UTF-8'))
|
channel.basic_publish(exchange="test",routing_key="test",body=binstring)
|
||||||
except Exception:
|
except Exception:
|
||||||
connection.close()
|
connection.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user