ProducerConfig

ProducerConfig is the configuration of a Kafka Producer.

ProducerConfig is created when:

  • …​

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

BOOTSTRAP_SERVERS_CONFIG

(empty)

bootstrap.servers

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_CONFIG

16384

batch.size

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

BUFFER_MEMORY_CONFIG

32 * 1024 * 1024

buffer.memory

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.

CLIENT_ID_CONFIG

(empty)

client.id

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.

COMPRESSION_TYPE_CONFIG

none

compression.type

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).

CONNECTIONS_MAX_IDLE_MS_CONFIG

9 * 60 * 1000

connections.max.idle.ms

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

INTERCEPTOR_CLASSES_CONFIG

(empty)

interceptor.classes

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

KEY_SERIALIZER_CLASS_CONFIG

key.serializer

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

LINGER_MS_CONFIG

0

linger.ms

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

VALUE_SERIALIZER_CLASS_CONFIG

value.serializer

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

MAX_BLOCK_MS_CONFIG

60 * 1000

max.block.ms

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

MAX_REQUEST_SIZE_CONFIG

1024 * 1024

max.request.size

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

METADATA_MAX_AGE_CONFIG

5 * 60 * 1000

metadata.max.age.ms

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

METRICS_NUM_SAMPLES_CONFIG

metrics.num.samples

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

METRICS_RECORDING_LEVEL_CONFIG

metrics.recording.level

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

METRIC_REPORTER_CLASSES_CONFIG

metric.reporters

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

The JmxReporter is always included to register JMX statistics.

METRICS_SAMPLE_WINDOW_MS_CONFIG

metrics.sample.window.ms

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

PARTITIONER_CLASS_CONFIG

DefaultPartitioner

partitioner.class

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

RECONNECT_BACKOFF_MAX_MS_CONFIG

RECONNECT_BACKOFF_MS_CONFIG

RECEIVE_BUFFER_CONFIG

REQUEST_TIMEOUT_MS_CONFIG

30 * 1000

request.timeout.ms

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 replica.lag.time.max.ms (a broker configuration) to reduce the possibility of message duplication due to unnecessary producer retries.

Must be at least 0

RETRY_BACKOFF_MS_CONFIG

100

retry.backoff.ms

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

SEND_BUFFER_CONFIG

TRANSACTIONAL_ID_CONFIG

(empty)

transactional.id

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…​FIXME

Note
logUnused is used when…​FIXME

results matching ""

    No results matching ""