Producer and Consumer details Flashcards

1
Q

What are the steps to create a producer in Java?

A
  1. Create producer properties
  2. Create the producer
  3. Send data
  4. Flush and close the producer

The flush method is called automatically when closing the producer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What properties are set for a Kafka producer?

A
  1. key.serializer
  2. value.serializer

Both are set using StringSerializer.class.getName()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the producer.send() method do?

A

Sends data asynchronously to the Kafka topic.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the purpose of the producer.flush() method?

A

To send all data and block until done.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the default batch size for Kafka?

A

16kB.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

True or False: If the same key is sent to Kafka, it will always go to the same partition.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the initial steps to consume messages from Kafka with Java?

A
  1. Connect to Kafka
  2. Create consumer configs
  3. Create a consumer
  4. Subscribe to a topic
  5. Poll for data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the key properties set for a Kafka consumer?

A
  1. key.deserializer
  2. value.deserializer
  3. group.id
  4. auto.offset.reset

Example values include StringDeserializer.class.getName() and ‘earliest’ for auto.offset.reset.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the three values for auto.offset.reset?

A
  • none
  • earliest
  • latest
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What happens during a partition rebalance in Kafka?

A

Partitions are moved between consumers when a consumer leaves or joins a group.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is Eager Rebalance in Kafka?

A

All consumers stop polling and rejoin the group for new partition assignments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is Cooperative Rebalance in Kafka?

A

Reassigns a small subset of partitions while allowing other consumers to continue processing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the strategies for partition assignment in Kafka?

A
  • RangeAssignor
  • RoundRobin
  • StickyAssignor
  • CooperativeStickyAssignor
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does acks = 0 mean in Kafka producer settings?

A

Producer won’t wait for acknowledgement, leading to possible data loss.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does acks = 1 mean in Kafka producer settings?

A

Producer waits for leader acknowledgement, allowing for limited data loss.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does acks = all (acks = -1) mean in Kafka producer settings?

A

Producer waits for acknowledgement from all in-sync replicas, ensuring no data loss.

17
Q

What is the purpose of min.insync.replicas in Kafka?

A

Controls the minimum number of replicas that must acknowledge a write for it to be considered successful.

18
Q

What is an Idempotent Producer in Kafka?

A

A producer that guarantees no duplicate messages on network errors.

19
Q

What is the default compression type for Kafka producers?

A

none

20
Q

What are the advantages of using compression in Kafka?

A
  • Smaller producer request size
  • Faster data transfer
  • Better throughput
  • Improved disk utilization
21
Q

What are the disadvantages of using compression in Kafka?

A
  • Producers must commit CPU cycles to compression
  • Consumers must commit CPU cycles to decompression
22
Q

What setting allows for increased batching in Kafka producers?

A

linger.ms.

23
Q

Fill in the blank: The rule ‘same key goes to the same partition’ is true unless the number of ______ changes.

A

partitions.