consumer.py –server kafka:9092 –consumer_group group1 –topic test-topic1 –messages 100 –sleep 1
import sys
import time
import argparse
#consumer.py --server kafka:9092 --consumer_group group1 --topic test-topic1 --messages 100 --sleep 1
parser = argparse.ArgumentParser(description='Optional app description')
parser.add_argument('--server', type=str,
help='kafka server with port eg. kafka:9092.')
parser.add_argument('--consumer_group', type=str,
help='consumer_group name.')
parser.add_argument('--topic', type=str,
help='kafka topic name')
parser.add_argument('--messages', type=int,
help='number of message needs to be produced.')
parser.add_argument('--sleep', type=int,
help='sleep between message produced.')
args = parser.parse_args()
print("kafka arguments:")
print(args.kafka_server,args.consumer_group,args.topic,args.messages,args.sleep)
More – https://stackoverflow.com/questions/20063/whats-the-best-way-to-parse-command-line-arguments
https://docs.python.org/3/library/argparse.html