Kafka MCQs – Kafka Java Client Programming

11.) Which method is used to subscribe to Kafka topics in the consumer?

A) register()
B) subscribe()
C) listen()
D) readFrom()

Answer: Option B

Explanation: The subscribe() method registers the consumer to one or more topics.

12.) What type of parameter does subscribe() accept?

A) A single topic name string
B) An array of strings
C) A list of strings
D) A map of topics

Answer: Option C

Explanation: You can pass a List<String> containing topic names.

13.) What does the poll() method do in KafkaConsumer?

A) Sends messages to the topic
B) Requests topic metadata
C) Creates a consumer group
D) Fetches records from Kafka

Answer: Option D

Explanation: poll() retrieves records from the subscribed topics.

14.) What object does poll() return?

A) ConsumerRecord
B) Map<String, String>
C) ConsumerRecords
D) String[]

Answer: Option C

Explanation: poll() returns a batch of ConsumerRecords.

15.) What must be done after consuming messages using manual offset management?

A) Call flush()
B) Call commitSync() or commitAsync()
C) Call close()
D) Nothing, Kafka handles it

Answer: Option B

Explanation: These methods are used to manually commit offsets after processing.

16.) What does the auto.offset.reset property control?

A) How offsets are synced
B) What offset to use when no offset is found
C) Retry policy
D) Producer buffering strategy

Answer: Option B

Explanation: It can be set to earliest, latest, or none.It can be set to earliest, latest, or none.

17.) What happens if enable.auto.commit is set to false?

A) Consumer must commit offsets manually
B) Kafka auto-deletes the messages
C) Kafka assigns no partitions
D) Consumer can’t consume from topics

Answer: Option A

Explanation: This allows you to manage when offsets are committed.

18.) What class encapsulates messages consumed from Kafka?

A) ConsumerRecord
B) KafkaMessage
C) MessageObject
D) KafkaMessageWrapper

Answer: Option A

Explanation: Each message in a topic is represented as a ConsumerRecord.

19.) Which property is used to specify a consumer group ID?

A) kafka.group.name
B) consumer.group
C) group.id
D) consumer.group.name

Answer: Option C

Explanation: The group.id config identifies the consumer group a consumer belongs to.

20.) What happens when two consumers share the same group ID?

A) They will receive duplicate messages
B) Kafka will split partitions among them
C) Only one of them can consume
D) Messages will be lost

Answer: Option B

Explanation: Kafka uses group IDs to coordinate partition assignment.

Leave a Reply

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