0
0
Kafkadevops~10 mins

Partition concept in Kafka - Interactive Code Practice

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

Complete the code to specify the number of partitions when creating a Kafka topic.

Kafka
new NewTopic("my-topic", [1], (short) 1);
Drag options to blanks, or click blank then click option'
A0
B3
C-1
D"3"
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero or negative numbers for partitions.
Using a string instead of an integer.
2fill in blank
medium

Complete the code to send a message to a specific partition in Kafka.

Kafka
producer.send(new ProducerRecord<>("my-topic", [1], "key", "value"));
Drag options to blanks, or click blank then click option'
A1
B"partition"
C"1"
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of an integer for partition.
Passing null when a specific partition is required.
3fill in blank
hard

Fix the error in the code to correctly create a Kafka topic with partitions.

Kafka
NewTopic topic = new NewTopic("my-topic", [1], (short) 1);
Drag options to blanks, or click blank then click option'
A"3"
B0
C3
D-3
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of an integer.
Using zero or negative numbers.
4fill in blank
hard

Fill both blanks to create a ProducerRecord that sends a message to partition 2 with key "user1".

Kafka
ProducerRecord<String, String> record = new ProducerRecord<>("my-topic", [1], [2], "message");
Drag options to blanks, or click blank then click option'
A2
B"user1"
C"user2"
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping partition and key positions.
Using integers for keys or strings for partitions.
5fill in blank
hard

Fill all three blanks to create a NewTopic with name "events", 4 partitions, and replication factor 2.

Kafka
NewTopic topic = new NewTopic([1], [2], (short) [3]);
Drag options to blanks, or click blank then click option'
A"events"
B4
C2
D"4"
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings for numbers.
Mixing up partitions and replication factor.