summary refs log tree commit diff
path: root/kafka-send/kafka-send.py
diff options
context:
space:
mode:
authorStarfall <us@starfall.systems>2024-07-02 17:26:40 -0500
committerStarfall <us@starfall.systems>2024-07-02 17:27:28 -0500
commita381884d323b67844d0ed7910b37171560a2d9d3 (patch)
treeaa61a0c54cbbed8da20fcafdfded3e110b1e3991 /kafka-send/kafka-send.py
parentd0649d2d83171a50d538c3690ede74dba7d12dc9 (diff)
kafka-send: new python script to produce kafka messages HEAD main
Diffstat (limited to 'kafka-send/kafka-send.py')
-rwxr-xr-xkafka-send/kafka-send.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/kafka-send/kafka-send.py b/kafka-send/kafka-send.py
new file mode 100755
index 0000000..b8ef414
--- /dev/null
+++ b/kafka-send/kafka-send.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python3
+import argparse
+import kafka
+
+parser = argparse.ArgumentParser()
+parser.add_argument('-s', '--server', default='localhost:9092', help='kafka bootstrap server (default localhost:9092)')
+parser.add_argument('topic', help='kafka topic')
+parser.add_argument('filename', help='file containing the message to be sent')
+args = parser.parse_args()
+
+with open(args.filename, 'r') as file:
+	msg = ''.join(file.readlines()).encode()
+
+producer = kafka.KafkaProducer(bootstrap_servers=args.server)
+producer.send(args.topic, msg)
+producer.flush()