0
0
Kafkadevops~10 mins

Partition count strategy 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 set the number of partitions when creating a Kafka topic.

Kafka
NewTopic topic = new NewTopic("my-topic", [1], (short) 1);
Drag options to blanks, or click blank then click option'
A"3"
BnumPartitions
Cpartitions
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of an integer for partitions.
Using a variable name without declaration.
2fill in blank
medium

Complete the code to retrieve the partition count of a Kafka topic using AdminClient.

Kafka
DescribeTopicsResult result = adminClient.describeTopics(Collections.singleton("my-topic"));
Map<String, TopicDescription> descriptions = result.all().get();
int partitionCount = descriptions.get("my-topic").[1]().size();
Drag options to blanks, or click blank then click option'
Apartitions
BgetPartitionCount
CgetPartitions
DpartitionsCount
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method that does not exist like getPartitionCount.
Using a field name instead of a method.
3fill in blank
hard

Fix the error in the code that sets the partition count dynamically based on a variable.

Kafka
int partitions = 5;
NewTopic topic = new NewTopic("my-topic", [1], (short) 1);
Drag options to blanks, or click blank then click option'
A"partitions"
Bpartitions
Cpartitions.toString()
DInteger.parseInt(partitions)
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the variable name in quotes making it a string.
Trying to parse an int variable as if it were a string.
4fill in blank
hard

Fill both blanks to create a topic with a partition count and replication factor.

Kafka
NewTopic topic = new NewTopic("my-topic", [1], (short) [2]);
Drag options to blanks, or click blank then click option'
A4
B2
C1
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using replication factor greater than available brokers.
Using zero or negative numbers.
5fill in blank
hard

Fill all three blanks to create a topic and check if the partition count is greater than 3.

Kafka
NewTopic topic = new NewTopic("my-topic", [1], (short) [2]);
int count = topic.[3]();
if (count > 3) {
    System.out.println("Many partitions");
}
Drag options to blanks, or click blank then click option'
A5
B1
CnumPartitions
Dpartitions
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method name to get partition count.
Using replication factor as partition count.