-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsumer.py
More file actions
53 lines (45 loc) · 1.26 KB
/
consumer.py
File metadata and controls
53 lines (45 loc) · 1.26 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
import sys as s
import socket as soc
import argparse as ap
import time as t
parse = ap.ArgumentParser()
parse.add_argument('--fromBeginning', required=True)
arguments = parse.parse_args()
off_set = arguments.fromBeginning
def brokerRequest(cons,address_ip,port_master):
PORT = int(port_master)
cons.connect((address_ip,PORT))
cons.send("conss".encode('utf-8'))
cons.send(('{"topic":"test1","offset":"' + off_set + '"}').encode('utf-8'))
while True:
result = cons.recv(1024).decode('utf-8')
if result:
print(result.strip())
else:
break
def zookeeperReq(cons,address_ip):
PORT = 2181
cons.connect((address_ip, PORT))
cons.send("cons".encode('utf-8'))
port_master = cons.recv(1024).decode('utf-8')
print(port_master)
cons.close()
return port_master
if __name__ == '__main__':
while True:
try:
cons = soc.socket(soc.AF_INET,soc.SOCK_STREAM)
print("Socket successfully created!!")
name_host = soc.gethostname()
address_ip = soc.gethostbyname(name_host)
port_master = zookeeperReq(cons,address_ip)
except soc.error as e:
continue
try:
cons = soc.socket(soc.AF_INET,soc.SOCK_STREAM)
print("Socket successfully created!!")
brokerRequest(cons,address_ip,port_master)
cons.close()
except soc.error as e:
continue
t.sleep(6)