Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to set the number of partitions for a Kafka topic.
Kafka
newTopic = NewTopic('my-topic', [1], replication_factor=1)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of an integer for partitions.
Confusing replication_factor with partitions.
✗ Incorrect
The number of partitions must be an integer, so 3 is correct.
2fill in blank
mediumComplete the code to configure the consumer group id.
Kafka
consumer = KafkaConsumer('my-topic', group_id=[1], bootstrap_servers=['localhost:9092'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number instead of a string for group_id.
Setting group_id to None disables consumer group behavior.
✗ Incorrect
The group_id must be a string identifying the consumer group.
3fill in blank
hardFix the error in setting the retention time for a topic.
Kafka
topic_config = {'retention.ms': [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of an integer for retention.ms.
Adding units like 'ms' inside the value.
✗ Incorrect
Kafka expects retention.ms as an integer representing milliseconds.
4fill in blank
hardFill both blanks to create a producer with acks set to all and retries set to 5.
Kafka
producer = KafkaProducer(acks=[1], retries=[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number for acks instead of a string.
Setting retries as a string.
✗ Incorrect
Setting acks to 'all' ensures all replicas acknowledge. Retries should be an integer like 5.
5fill in blank
hardFill all three blanks to create a topic with 4 partitions, replication factor 2, and cleanup policy set to compact.
Kafka
newTopic = NewTopic('[1]', [2], replication_factor=[3], topic_configs={'cleanup.policy': 'compact'})
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong data types for partitions or replication factor.
Confusing replication factor with partitions.
✗ Incorrect
The topic name is 'my-topic', partitions are 4, and replication factor is 2 for fault tolerance.