Skip to content

Commit 05a84f8

Browse files
add security modes support:SSL, PLAINTEXT.
add check arg
1 parent c53a171 commit 05a84f8

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ pip install -r requirements.txt
2323

2424
## Usage
2525

26-
The Python code can be run in bash with the following
27-
26+
The Python code can be run in bash with the following,
27+
in SSL security protocol:
2828
```bash
29-
python main.py --cert-folder ~/kafkaCerts/ \
29+
python main.py --security-protocol ssl --cert-folder ~/kafkaCerts/ \
3030
--host kafka-<name>.aivencloud.com \
3131
--port 13041 \
3232
--topic-name pizza-orders \

main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
from kafka import KafkaProducer
44
import time
5+
import sys
56
import random
67
import argparse
78
from pizzaproducer import PizzaProvider
@@ -38,7 +39,7 @@ def produce_msgs(security_protocol='SSL',
3839
value_serializer=lambda v: json.dumps(v).encode('ascii'),
3940
key_serializer=lambda v: json.dumps(v).encode('ascii')
4041
)
41-
else:
42+
elif security_protocol.upper() == 'SSL':
4243
producer = KafkaProducer(
4344
bootstrap_servers=hostname + ':' + port,
4445
security_protocol='SSL',
@@ -48,6 +49,8 @@ def produce_msgs(security_protocol='SSL',
4849
value_serializer=lambda v: json.dumps(v).encode('ascii'),
4950
key_serializer=lambda v: json.dumps(v).encode('ascii')
5051
)
52+
else:
53+
sys.exit("This security protocol is not supported!")
5154

5255
if nr_messages <= 0:
5356
nr_messages = float('inf')

0 commit comments

Comments
 (0)