0
0
Kafkadevops~10 mins

Why distributed architecture ensures reliability in Kafka - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a Kafka producer that sends messages to a topic.

Kafka
producer = KafkaProducer(bootstrap_servers='localhost:9092')
producer.send('[1]', b'Hello Kafka')
producer.flush()
Drag options to blanks, or click blank then click option'
Alocalhost
Bmessage_topic
Ckafka_server
Dmy_topic
Attempts:
3 left
💡 Hint
Common Mistakes
Using server names instead of topic names in the send method.
2fill in blank
medium

Complete the code to consume messages from a Kafka topic.

Kafka
consumer = KafkaConsumer('[1]', bootstrap_servers='localhost:9092')
for message in consumer:
    print(message.value)
Drag options to blanks, or click blank then click option'
Aserver
Bmy_topic
Cconsumer_group
Dlocalhost
Attempts:
3 left
💡 Hint
Common Mistakes
Using server or group names instead of topic names.
3fill in blank
hard

Fix the error in the code to ensure the Kafka consumer joins the correct consumer group.

Kafka
consumer = KafkaConsumer('my_topic', bootstrap_servers='localhost:9092', group_id=[1])
for message in consumer:
    print(message.value)
Drag options to blanks, or click blank then click option'
A'my_group'
B123
CNone
Dlocalhost
Attempts:
3 left
💡 Hint
Common Mistakes
Passing None or numbers instead of a string for group_id.
4fill in blank
hard

Fill both blanks to create a Kafka topic with 3 partitions and a replication factor of 2.

Kafka
topic_config = NewTopic(name='my_topic', num_partitions=[1], replication_factor=[2])
Drag options to blanks, or click blank then click option'
A3
B1
C2
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using replication factor 1 which does not provide redundancy.
5fill in blank
hard

Fill all three blanks to configure a Kafka producer with retries, acks, and a timeout for reliability.

Kafka
producer = KafkaProducer(bootstrap_servers='localhost:9092', retries=[1], acks=[2], request_timeout_ms=[3])
Drag options to blanks, or click blank then click option'
A0
B'all'
C30000
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Setting retries to 0 disables retrying.
Using acks=1 or acks=0 reduces reliability.