← ZIO Kafka docs

ProducerSettings

zio.kafka.producer.ProducerSettings
See theProducerSettings companion object
final case class ProducerSettings(closeTimeout: Duration = ..., sendBufferSize: Int = ..., authErrorRetrySchedule: Schedule[Any, Throwable, Any] = ..., properties: Map[String, AnyRef] = ..., diagnostics: ProducerDiagnostics = ..., metricLabels: Set[MetricLabel] = ..., metricsObserver: Option[ProducerMetricsObserver] = ...)

Settings for the Producer.

To stay source compatible with future releases, you are recommended to construct the settings as follows:

 ProducerSettings(bootstrapServers)
   .withLinger(500.millis)
   .withCompression(ProducerCompression.Zstd(3))
   .... etc.

Attributes

Companion
object
Source
ProducerSettings.scala
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def driverSettings: Map[String, AnyRef]

Attributes

Source
ProducerSettings.scala
def withAuthErrorRetrySchedule(authErrorRetrySchedule: Schedule[Any, Throwable, Any]): ProducerSettings

Configure retries for authorization or authentication errors.

Configure retries for authorization or authentication errors.

If you want to retry other (retriable) exceptions, please use the retries configuration property.

⚠️ Retrying may cause records to be produced in a different order than the order in which they were given to zio-kafka.

Value parameters

authErrorRetrySchedule

The schedule at which the producer will retry producing, even when producing fails with an org.apache.kafka.common.errors.AuthorizationException or org.apache.kafka.common.errors.AuthenticationException. This setting helps with failed producing due to too slow authorization or authentication in the broker. For example, to retry 5 times, spaced by 500ms, you can set this to

Schedule.recurs(5) && Schedule.spaced(500.millis)

The default is Schedule.stop which is, to fail the producer on the first auth error.

Attributes

Source
ProducerSettings.scala

Attributes

Source
ProducerSettings.scala

Value parameters

compression

The compression codec to use when publishing records. Compression is of full batches of data, so the efficacy of batching will also impact the compression ratio (more batching means better compression). See also withLinger.

Attributes

Source
ProducerSettings.scala

Value parameters

diagnostics

an optional callback for key events in the producer life-cycle. The callbacks will be executed in a separate fiber. Since the events are queued, failure to handle these events leads to out of memory errors.

Attributes

Source
ProducerSettings.scala

Value parameters

idempotence

when true (the default) the producer writes idempotently: each record is assigned a sequence number so the broker can deduplicate retries, guaranteeing exactly-once, in-order delivery per partition. Set to false to disable sequence tracking (e.g. for tests, or high-throughput producing where occasional duplicates on retry are acceptable).

Attributes

Source
ProducerSettings.scala
def withLinger(lingerDuration: Duration): ProducerSettings

Value parameters

lingerDuration

The maximum amount of time a record is allowed to linger in the producer's internal buffer. Higher values allow for better batching (especially important when compression is used), lower values reduce latency and memory usage.

Attributes

Source
ProducerSettings.scala

Value parameters

metricLabels

The labels given to all metrics collected by the zio-kafka producer. By default, no labels are set. For applications with multiple producers it is recommended to set some metric labels. For example, one can imagine a producer-id that can be used as a label:

 producerSettings.withMetricsLabels(Set(MetricLabel("producer-id", producerId)))

This setting is ignored when an alternative metrics observer is set.

Attributes

Source
ProducerSettings.scala

Value parameters

observer

a custom zio.kafka.producer.metrics.ProducerMetricsObserver implementation for collecting producer metrics. When not set, the default zio-metrics based implementation is used. Use this to integrate with alternative metrics backends (Dropwizard, Micrometer, etc.) or to customize histogram boundaries. Use zio.kafka.producer.metrics.ProducerMetricsObserver.NoOp to disable metric collection.

Attributes

Source
ProducerSettings.scala
def withProperties(kvs: (String, AnyRef)*): ProducerSettings

Attributes

Source
ProducerSettings.scala

Attributes

Source
ProducerSettings.scala
def withProperty(key: String, value: AnyRef): ProducerSettings

Attributes

Source
ProducerSettings.scala
def withSendBufferSize(sendBufferSize: Int): ProducerSettings

Value parameters

sendBufferSize

The maximum number of record chunks that can queue up while waiting for the underlying producer to become available. Performance critical users that publish a lot of records one by one (instead of in chunks), should consider increasing this value, for example to 10240.

Attributes

Source
ProducerSettings.scala

Inherited methods

An iterator over the names of all the elements of this product.

An iterator over the names of all the elements of this product.

Attributes

Inherited from:
Product
Source
Product.scala

An iterator over all the elements of this product.

An iterator over all the elements of this product.

Attributes

Returns

in the default implementation, an Iterator[Any]

Inherited from:
Product
Source
Product.scala