blob: b8ef414ffb4acac53e7ebb637b8d527e3956ce52 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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()
|