aligning with book example
This commit is contained in:
@@ -1,25 +1,14 @@
|
|||||||
from kafka import KafkaConsumer
|
from kafka import KafkaConsumer
|
||||||
import json, sys
|
import json, sys
|
||||||
host_id = '10.52.90.101:9092'
|
host_id = '10.52.90.10:9092'
|
||||||
topic_id = 'NSP-EQUIPMENT'
|
topicid = 'ns-eg-ff15a252-f927-48c7-a98f-2965ab6c187d'
|
||||||
consumer = KafkaConsumer(bootstrap_servers=['10.52.90.101:9092'],
|
consumer = KafkaConsumer(topicid,
|
||||||
auto_offset_reset='earliest',
|
group_id='120',
|
||||||
consumer_timeout_ms=1000,
|
bootstrap_servers=['10.52.90.10:9092'], value_deserializer=lambda m: json.loads(m.decode('ascii')),
|
||||||
api_version=(0, 10, 1))
|
api_version=(0, 10, 1))
|
||||||
consumer.subscribe([topic_id])
|
|
||||||
print(consumer)
|
|
||||||
try:
|
|
||||||
for message in consumer:
|
|
||||||
print(message)
|
|
||||||
if message is None:
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
msg = json.loads(message.value)
|
|
||||||
print(json.dumps(msg, indent=4, sort_keys=True))
|
|
||||||
|
|
||||||
|
for message in consumer:
|
||||||
except KeyboardInterrupt:
|
print("%s:%d:%d: key=%s value=%s" % (message.topic, message.partition,
|
||||||
sys.stderr.write('++++++ Aborted by user ++++++++\n')
|
message.offset, message.key,
|
||||||
|
message.value))
|
||||||
finally:
|
|
||||||
consumer.close()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user