ProducerConfig

ProducerConfig is the configuration of a Kafka Producer.

ProducerConfig is created when:

  • …​

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

ACKS_CONFIG

Default: 1

Property: acks

The number of acknowledgments a producer requires the leader to have received before considering a request complete. This controls the durability of records that are sent.

The following settings are allowed:

  • 0 - a producer will not wait for any acknowledgment from the server at all. The record will be immediately added to the socket buffer and considered sent. No guarantee can be made that the server has received the record in this case, and the retries configuration will not take effect (as the client won’t generally know of any failures). The offset given back for each record will always be set to -1.

  • 1 (default) - the leader will write the record to its local log but will respond without awaiting full acknowledgement from all followers. In this case should the leader fail immediately after acknowledging the record but before the followers have replicated it then the record will be lost.

  • all or -1 - the leader will wait for the full set of in-sync replicas to acknowledge the record. This guarantees that the record will not be lost as long as at least one in-sync replica remains alive. This is the strongest available guarantee.

BOOTSTRAP_SERVERS_CONFIG

Default: (empty)

Property: 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

Default: 16384

Property: batch.size

Batch size (in bytes)

A Kafka 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

Default: 32 * 1024 * 1024

Property: buffer.memory

The total bytes of memory a Kafka 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

Default: (empty)

Property: 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

Default: none

Property: 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

Default: 9 * 60 * 1000

Property: connections.max.idle.ms

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

DELIVERY_TIMEOUT_MS_CONFIG

Default: 120 * 1000

Property: delivery.timeout.ms

An upper bound on the time to report a success or a failure after a call to send() returns. This limits the total time that a record will be delayed prior to sending, the time to await acknowledgement from the broker (if expected), and the time allowed for retriable send failures.

A Kafka producer may report failure to send a record earlier than this config if either an unrecoverable error is encountered, the retries have been exhausted, or the record is added to a batch which reached an earlier delivery expiration deadline.

The value of this config should be greater than or equal to the sum of request.timeout.ms and linger.ms.

Must be at least 0

ENABLE_IDEMPOTENCE_CONFIG

Default: false

Property: enable.idempotence

When enabled (true), a producer will ensure that exactly one copy of a message is written to the stream.

When disabled (false), it is acceptable that a producer may write duplicates of a message to the stream (e.g. due to broker failures and retries).

Enabling idempotence requires:

If these values are not explicitly set, suitable values will be chosen. If incompatible values are set, a ConfigException will be thrown.

INTERCEPTOR_CLASSES_CONFIG

Default: (empty)

Property: 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

Default: (empty)

Property: key.serializer

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

LINGER_MS_CONFIG

Default: 0

Property: 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.

Must be at least 0

MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION

Default: 5

Property: max.in.flight.requests.per.connection

The maximum number of unacknowledged requests a client will send on a single connection before blocking.

Note that if this setting is set to be greater than 1 and there are failed sends, there is a risk of message re-ordering due to retries (i.e. if retries are enabled).

Must be at least 1

RETRIES_CONFIG

Default: Integer.MAX_VALUE

Property: retries

A value greater than 0 will cause the client to resend any record whose send fails with a potentially transient error.

Note that this retry is no different than if the client resent the record upon receiving the error.

Allowing retries without setting max.in.flight.requests.per.connection to 1 will potentially change the ordering of records because if two batches are sent to a single partition, and the first fails and is retried but the second succeeds, then the records in the second batch may appear first.

Note also that produce requests will be failed before the number of retries has been exhausted if the timeout configured by delivery.timeout.ms expires first before successful acknowledgement.

Users should generally prefer to leave this config unset and instead use delivery.timeout.ms to control retry behavior.

Must be at least 0

VALUE_SERIALIZER_CLASS_CONFIG

Property: value.serializer

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

MAX_BLOCK_MS_CONFIG

Default: 60 * 1000

Property: max.block.ms

How long can 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

Default: 1024 * 1024

Property: 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

Default: 5 * 60 * 1000

Property: 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

Property: metrics.num.samples

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

METRICS_RECORDING_LEVEL_CONFIG

Property: metrics.recording.level

The name of highest recording level for metrics.

Must be one of the following: INFO or DEBUG.

METRIC_REPORTER_CLASSES_CONFIG

Property: 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

Property: metrics.sample.window.ms

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

PARTITIONER_CLASS_CONFIG

Default: DefaultPartitioner

Property: 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

Default: 30 * 1000

Property: 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

Default: 100

Property: retry.backoff.ms

How long to wait (back off) 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

Used when KafkaProducer is created (for a RecordAccumulator, a Metadata, a Sender, and a TransactionManager)

SEND_BUFFER_CONFIG

TRANSACTION_TIMEOUT_CONFIG

Property: transaction.timeout.ms

The maximum amount of time (in ms) that the transaction coordinator will wait for a transaction status update from a producer before proactively aborting the ongoing transaction.

If this value is larger than transaction.max.timeout.ms configuration (of Kafka brokers), the request will fail with an InvalidTransactionTimeout error.

TRANSACTIONAL_ID_CONFIG

Default: (empty)

Property: transactional.id

User-defined 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.

enable.idempotence must be enabled (true) 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 ""