- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproduce.py
More file actions
Latest commit
34 lines (27 loc) · 818 Bytes
/
Copy pathproduce.py
File metadata and controls
34 lines (27 loc) · 818 Bytes
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
importrandom
importtime
fromconfluent_kafkaimportProducer
options= {
'bootstrap.servers': "localhost:29092",
'retries': 10,
'delivery.report.only.error': False, # if set to True, will not be able be able to count successful delivery
'message.max.bytes': 2097152
}
producer=Producer(**options)
count=0
defon_delivered(err, msg):
globalcount
iferr:
printerr, msg.value()
else:
printmsg.offset()
count+=1
withopen('/usr/share/dict/words') asfh:
forlineinfh:
word=line.strip()
# produce is asynchronous
producer.produce('words', word, on_delivery=on_delivered)
#time.sleep(random.random())
# need to force a flush so all data is sent
producer.flush()
print"{} messages delivered".format(count)