Complete the code to import the KafkaConsumer class from the kafka module.
from kafka import [1] consumer = KafkaConsumer('my_topic')
You need to import KafkaConsumer to create a consumer that reads messages from Kafka.
Complete the code to create a KafkaConsumer that reads from the topic 'orders'.
consumer = KafkaConsumer([1])The consumer should subscribe to the topic named 'orders' to read order messages.
Fix the error in the code to correctly consume messages from Kafka.
for message in consumer.[1](): print(message.value)
The method to iterate over messages is poll() or simply iterating over the consumer. Here, poll() is the correct method to get messages.
Fill both blanks to create a consumer that reads from 'events' topic and uses 'localhost:9092' as the Kafka server.
consumer = KafkaConsumer([1], bootstrap_servers=[2])
The topic name is 'events' and the Kafka server address is 'localhost:9092'.
Fill all three blanks to create a KafkaConsumer that reads from 'logs', connects to 'broker:9092', and uses 'earliest' offset reset.
consumer = KafkaConsumer([1], bootstrap_servers=[2], auto_offset_reset=[3])
The topic is 'logs', the server is 'broker:9092', and the offset reset policy is 'earliest' to start from the beginning of the topic.