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