-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
63 lines (55 loc) · 2.79 KB
/
main.py
File metadata and controls
63 lines (55 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import threading
from producer import producer_create
from producer import p_create
from consumer import consumer_create
from consumer import c_create
if __name__ == "__main__":
var = 1
while var == 1:
val = input("Would you like to produce or consume (enter 'p' or 'c'): ")
if val == "p" or val == "c":
use_ssl = input("Does the bootstrap use SASL/SSL? (enter 'yes' or 'no'): ")
bootstrap_servers = input("Please input bootstrap servers (ex. localhost:9092 or if in a docker container host.docker.internal:9092): ")
client_id = input("Please input a client id: ")
topic = input("Enter a topic name: ")
if use_ssl == "yes":
security_protocol = input("Enter the security protocol (ex. PLAIN_SASL): ")
sasl_mechanism = input("Enter the sasl mechanism (ex. PLAINTEXT): ")
sasl_plain_username = input("Enter a username: ")
sasl_plain_password = input("Enter a password: ")
ssl_context = input("Enter an ssl context: ")
if val == "p":
producer = producer_create(bootstrap_servers, client_id, security_protocol, sasl_mechanism,
sasl_plain_username, sasl_plain_password, ssl_context)
else:
consumer_create(topic, bootstrap_servers, client_id, security_protocol,
sasl_mechanism, sasl_plain_username, sasl_plain_password,
ssl_context)
t1 = threading.Thread(c_create(consumer))
t1.start()
else:
if val == "p":
producer = producer_create(bootstrap_servers, client_id)
if val == "p":
num_of_messages = input("Enter # of messages wanting to be sent: ")
num_of_messages = int(num_of_messages)
t1 = threading.Thread(p_create(producer, topic, num_of_messages))
t1.start()
if val == "c" and use_ssl != "yes":
consumer = consumer_create(topic, bootstrap_servers, client_id)
t1 = threading.Thread(c_create(consumer))
t1.start()
else:
print("Incorrect value for producer or consumer")
# Multiprocess setup notes ...
#proc1 = mp.Process(target=c_create, args=["c1"])
#proc1.start()
#proc1.join()
# Timing work ...
#d = {}
#start_time = time.time()
#for i in range(1, 2000):
# d["proc{0}".format(i)] = mp.Process(target=c_create, args=["c{0}".format(i)])
# d["proc{0}".format(i)].start()
# print(i)
#print("--- %s seconds ---" % (time.time() - start_time))