-
Notifications
You must be signed in to change notification settings - Fork 5
/
kafka_server.py
38 lines (30 loc) · 902 Bytes
/
kafka_server.py
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
import producer_server
import time
def run_kafka_server():
# Get the json file path
input_file = "police-department-calls-for-service.json"
# Create a Producer Server.
producer = producer_server.ProducerServer(
input_file=input_file,
topic="police.service.calls",
bootstrap_servers="localhost:9092",
client_id=None
)
if producer.bootstrap_connected():
print("Connected to bootstrap")
return producer
# Feed data to topic
def feed():
producer = run_kafka_server()
try:
producer.generate_data()
except:
producer.counter = 0
producer.flush()
producer.close()
#Driver for Kafka Producer
if __name__ == "__main__":
start = time.time()
feed()
end = time.time()
print(f"Program start time : {start}\nProgram end time : {end}\nExecution time : {round(end - start,2)}")