Complete the code to create a Kafka consumer that subscribes to a topic.
consumer.subscribe([[1]])The subscribe method requires a list of topic names as strings. So the topic name must be in quotes inside a list.
Complete the code to set the consumer group id for Kafka monitoring.
consumer_config = {"group.id": [1]The group.id must be a string, so it needs quotes.
Fix the error in the code to poll messages from Kafka with a timeout of 1 second.
msg = consumer.poll(timeout_ms=[1])The poll method expects timeout_ms in milliseconds as an integer, so 1000 means 1 second.
Fill both blanks to configure Kafka consumer to auto-commit offsets and set auto offset reset to earliest.
consumer_config = {"enable.auto.commit": [1], "auto.offset.reset": [2]To auto-commit offsets, enable.auto.commit must be True. To start from the earliest message if no offset is found, auto.offset.reset must be 'earliest'.
Complete the code to create a dictionary comprehension that maps topic partitions to their current offsets if the offset is greater than 0.
offsets = {partition: offset for partition, offset in offsets_dict.items() if offset [1] 0}The dictionary keys and values are partition and offset directly, so no extra attribute is needed. The condition checks if offset is greater than 0.