ProducerConfig is the configuration of a Kafka Producer.

ProducerConfig is created when:

  • …​

Table 1. ProducerConfig’s Configuration Properties
Name Default Value Kafka Property Description




Host:port pairs to use to establish the initial connection to a Kafka cluster. The client will make use of all servers irrespective of which servers are specified here for bootstrapping, i.e. this list only impacts the initial hosts used to discover the full set of servers.

This list should be in the form host1:port1,host2:port2,…​

Since these servers are just used for the initial connection to discover the full cluster membership (which may change dynamically), this list need not contain the full set of servers (you may want more than one, though, in case a server is down).




Batch size (in bytes)

The producer will attempt to batch records together into fewer requests whenever multiple records are being sent to the same partition. This helps performance on both the client and the server.

No attempt will be made to batch records larger than this size.

Requests sent to brokers will contain multiple batches, one for each partition with data available to be sent.

A small batch size will make batching less common and may reduce throughput (a batch size of zero will disable batching entirely).

A very large batch size may use memory a bit more wastefully as we will always allocate a buffer of the specified batch size in anticipation of additional records.

Must be at least 0


32 * 1024 * 1024


The total bytes of memory a producer can use to buffer records waiting to be sent to the server.

If records are sent faster than they can be delivered to the server the producer will block for MAX_BLOCK_MS_CONFIG after which it will throw an exception.

This setting should correspond roughly to the total memory the producer will use, but is not a hard bound since not all memory the producer uses is used for buffering. Some additional memory will be used for compression (if compression is enabled) as well as for maintaining in-flight requests.



An id string to pass to the server when making requests. The purpose of this is to be able to track the source of requests beyond just ip/port by allowing a logical application name to be included in server-side request logging.




The compression type for all data generated by the producer. The default is none (i.e. no compression).

Valid values are none, gzip, snappy, or lz4.

Compression is of full batches of data, so the efficacy of batching will also impact the compression ratio (more batching means better compression).


9 * 60 * 1000

Close idle connections after the number of milliseconds specified by this config.




ProducerInterceptors to use to intercept (and possibly mutate) the records sent out by the producer before they are published to the Kafka cluster.



Serializer class for keys that implements the org.apache.kafka.common.serialization.Serializer interface.



The producer groups together any records that arrive in between request transmissions into a single batched request. Normally this occurs only under load when records arrive faster than they can be sent out. However in some circumstances the client may want to reduce the number of requests even under moderate load. This setting accomplishes this by adding a small amount of artificial delay, i.e. rather than immediately sending out a record the producer will wait for up to the given delay to allow other records to be sent so that the sends can be batched together. This can be thought of as analogous to Nagle’s algorithm in TCP. This setting gives the upper bound on the delay for batching: once we get BATCH_SIZE_CONFIG worth of records for a partition it will be sent immediately regardless of this setting, however if we have fewer than this many bytes accumulated for this partition we will 'linger' for the specified time waiting for more records to show up.

Default is 0 (i.e. no delay)

Must be at least 0



Serializer class for values that implements the org.apache.kafka.common.serialization.Serializer interface.


60 * 1000

How long KafkaProducer.send() and KafkaProducer.partitionsFor() block.

These methods can be blocked either because the buffer is full or metadata unavailable. Blocking in the user-supplied serializers or partitioner will not be counted against this timeout.

Must be at least 0


1024 * 1024


The maximum size of a request in bytes. This setting will limit the number of record batches the producer will send in a single request to avoid sending huge requests. This is also effectively a cap on the maximum record batch size.

Note that the server has its own cap on record batch size which may be different.

Must be at least 0


5 * 60 * 1000

The period of time (in milliseconds) after which we force a refresh of metadata even if we haven’t seen any partition leadership changes to proactively discover any new brokers or partitions.

Must be at least 0



The number of samples maintained to compute metrics (for Kafka producers). Must be at least 1.



The name of highest recording level for metrics. Must be one of the following: INFO or DEBUG.



The class names of the MetricsReporters that will be notified of new metric creation.

The JmxReporter is always included to register JMX statistics.


The window of time a metrics sample is computed over (for Kafka producers).




The Partitioner to compute the partition for a record when KafkaProducer is requested to send a record to topic.





30 * 1000

Maximum amount of time the client will wait for the response of a request. If the response is not received before the timeout elapses the client will resend the request if necessary or fail the request if retries are exhausted.

This should be larger than (a broker configuration) to reduce the possibility of message duplication due to unnecessary producer retries.

Must be at least 0



The amount of time to wait before attempting to retry a failed request to a given topic partition. This avoids repeatedly sending requests in a tight loop under some failure scenarios.

Must be at least 0




The Transactional ID to use for transactional delivery. This enables reliability semantics which span multiple producer sessions since it allows the client to guarantee that transactions using the same Transactional ID have been completed prior to starting any new transactions.

With no Transactional ID provided, the producer is limited to idempotent delivery. Note that enable.idempotence must be enabled if a Transactional ID is configured.

The default means transactions cannot be used.

Note that transactions requires a cluster of at least 3 brokers by default what is the recommended setting for production; for development you can change this, by adjusting broker setting transaction.state.log.replication.factor.

logUnused Method

void logUnused()


logUnused is used when…​FIXME

results matching ""

    No results matching ""