Kafka MCQs – Kafka Java Client Programming

21.) How can a producer flush pending records to Kafka?

A) Call commit()
B) Call sync()
C) Call flush()
D) Call send() again

Answer: Option C

Explanation: flush() ensures all buffered records are sent.

22.) Which serializer is used for sending String data?

A) JsonSerializer
B) ByteSerializer
C) ObjectSerializer
D) StringSerializer

Answer: Option D

Explanation: org.apache.kafka.common.serialization.StringSerializer is used for serializing strings.

23.) What is the main benefit of using callback with send()?

A) It retries automatically
B) It gives sync behavior
C) It notifies when the message is acknowledged
D) It disables batching

Answer: Option C

Explanation: Callback helps to handle success/failure of message send operation.

24.) Which property sets the maximum size of a Kafka message?

A) message.size.max
B) max.message.bytes
C) message.max.bytes
D) max.request.size

Answer: Option D

Explanation: This controls the maximum size of a message sent by the producer.

25.) Which config in KafkaConsumer limits the number of records per poll()?

A) max.poll.records
B) poll.size.max
C) batch.size
D) poll.limit

Answer: Option A

Explanation: This controls the number of records returned in a single poll().

26.) What happens when a KafkaProducer is not closed?

A) Messages are lost
B) It auto-closes
C) JVM throws an error
D) Resources like threads may leak

Answer: Option D

Explanation: Always close KafkaProducer to release resources.

27.) What is the typical polling interval for consumers?

A) Every second
B) Controlled by poll() timing
C) Every 5 minutes
D) Kafka controls it internally

Answer: Option B

Explanation: The application controls polling frequency using poll().

28.) What is the role of Kafka callback interface?

A) Serializing records
B) Modifying partitions
C) Handling errors or success in send()
D) Logging consumer offsets

Answer: Option C

Explanation: Callback is used to handle success or exceptions in producer delivery.

29.) What class provides metadata for sent records in the producer?

A) RecordMetadata
B) RecordMetadata
C) SendMetadata
D) MessageMeta

Answer: Option B

Explanation: RecordMetadata provides info like topic, partition, offset after sending.

30.) Which Kafka client version introduced KafkaAdminClient for Java-based admin operations?

A) 0.8
B) 0.10
C) 1.0
D) 2.0

Answer: Option D

Explanation: Kafka 2.0 introduced the KafkaAdminClient to perform admin tasks using Java code.

Leave a Reply

Your email address will not be published. Required fields are marked *