Sender is a Kafka producer I/O thread (of execution) that sends produce requests to a Kafka cluster.

Figure 1. Sender and KafkaProducer

Sender is created exclusively when KafkaProducer is created.

Sender is started under the name kafka-producer-network-thread | [clientId] when KafkaProducer is created.

Table 1. Sender’s Internal Properties (e.g. Registries and Counters)
Name Description


Flag that controls whether run should finish or not

sendProduceRequests Internal Method

void sendProduceRequests(Map<Integer, List<ProducerBatch>> collated, long now)


sendProduceRequests is used exclusively when Sender is requested to sendProducerData.

sendProduceRequest Internal Method

void sendProduceRequest(
  long now,
  int destination,
  short acks,
  int timeout,
  List<ProducerBatch> batches)


sendProduceRequest is used exclusively when Sender is requested to sendProduceRequests.

sendProducerData Internal Method

long sendProducerData(long now)


sendProducerData is used exclusively when Sender is requested to runs a single iteration of sending.

Running Single Iteration of Sending — run Method

void run(long now)

run does…​FIXME…​when the transactionManager is available.

run sendProducerData and then requests the KafkaClient to poll.

run is used exclusively when Sender is requested to start (as a thread of execution).

Starting Thread of Execution — run Method (of Java’s Runnable)

void run()
run is a part of java.lang.Runnable that is executed when the thread is started.

run first prints out the following DEBUG message to the logs:

Starting Kafka producer I/O thread.

run keeps running until the running flag is off.


Creating Sender Instance

Sender takes the following when created:

  • LogContext

  • KafkaClient

  • Metadata

  • RecordAccumulator

  • guaranteeMessageOrder flag

  • maxRequestSize

  • acks

  • The number of retries

  • SenderMetricsRegistry

  • Time

  • requestTimeout

  • retryBackoffMs

  • TransactionManager

  • ApiVersions

Sender initializes the internal registries and counters.

results matching ""

    No results matching ""