- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsume.py
More file actions
Latest commit
26 lines (22 loc) · 589 Bytes
/
Copy pathconsume.py
File metadata and controls
26 lines (22 loc) · 589 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
fromconfluent_kafkaimportConsumer
fromconfluent_kafka.cimplimportKafkaError
c=Consumer({
'bootstrap.servers': "localhost:29092",
'group.id': 'mygroup',
'default.topic.config': {
'auto.offset.reset': 'smallest'
}
})
c.subscribe(['words'])
whileTrue:
msg=c.poll(1.0)
ifmsgisNone:
continue
ifmsg.error():
ifmsg.error().code() ==KafkaError._PARTITION_EOF:
continue
else:
print(msg.error())
break
print(u'Received message: {}'.format(msg.value().decode('utf-8')))
c.close()