Class KafkaConfigBuilder

    • Method Detail

      • bootstrapServers

        public KafkaConfigBuilder bootstrapServers​(String servers)
        A list of host/port pairs to use for establishing the initial connection to the Kafka cluster. The client will make use of all servers irrespective of which servers are specified here for bootstrapping—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).
        • Type: list
        • Default: ""
        • Valid Values: non-null string
        Parameters:
        servers - list of host/port pairs
        Returns:
        this builder
      • topic

        public KafkaConfigBuilder topic​(String... topics)
        Names of the topics to consume from.
        Parameters:
        topics - topic name
        Returns:
        this builder
      • topicPattern

        public KafkaConfigBuilder topicPattern​(Pattern topicPattern)
        Pattern for topic names to consume from.
        Parameters:
        topicPattern - topic name regex pattern
        Returns:
        this builder
      • topicPattern

        public KafkaConfigBuilder topicPattern​(String topicPattern)
        Regex pattern for topic names to consume from.
        Parameters:
        topicPattern - topic name regex pattern
        Returns:
        this builder
      • groupId

        public KafkaConfigBuilder groupId​(String groupId)
        A unique string that identifies the consumer group this consumer belongs to. This property is required.
        • Type: string
        Parameters:
        groupId - consumer group identifier
        Returns:
        this builder
      • enableAutoCommit

        public KafkaConfigBuilder enableAutoCommit​(boolean enableAutoCommit)
        If true the consumer's offset will be periodically committed in the background.
        • Type: boolean
        • Default: true
        Parameters:
        enableAutoCommit - true for automatic offset committing
        Returns:
        this builder
      • keySerializer

        public KafkaConfigBuilder keySerializer​(Class<? extends org.apache.kafka.common.serialization.Serializer<?>> keySerializer)
        Serializer class for key that implements the Serializer interface.
        Parameters:
        keySerializer - class responsible for key serializing
        Returns:
        this builder
      • keyDeserializer

        public KafkaConfigBuilder keyDeserializer​(Class<? extends org.apache.kafka.common.serialization.Deserializer<?>> keyDeserializer)
        Deserializer class for key that implements the Deserializer interface.
        Parameters:
        keyDeserializer - class responsible for key de-serializing
        Returns:
        this builder
      • valueSerializer

        public KafkaConfigBuilder valueSerializer​(Class<? extends org.apache.kafka.common.serialization.Serializer<?>> valueSerializer)
        Serializer class for value that implements the Serializer interface.
        Parameters:
        valueSerializer - class responsible for value serializing
        Returns:
        this builder
      • valueDeserializer

        public KafkaConfigBuilder valueDeserializer​(Class<? extends org.apache.kafka.common.serialization.Deserializer<?>> valueDeserializer)
        Deserializer class for value that implements the Deserializer interface.
        Parameters:
        valueDeserializer - class responsible for value de-serializing
        Returns:
        this builder
      • pollTimeout

        public KafkaConfigBuilder pollTimeout​(long pollTimeout)
        The maximum time to block polling loop in milliseconds.
        Parameters:
        pollTimeout - time to block polling loop in milliseconds
        Returns:
        this builder
      • periodExecutions

        public KafkaConfigBuilder periodExecutions​(long periodExecutions)
        Period between successive executions of polling loop.
        Parameters:
        periodExecutions - in milliseconds
        Returns:
        this builder
      • autoOffsetReset

        public KafkaConfigBuilder autoOffsetReset​(KafkaConfigBuilder.AutoOffsetReset autoOffsetReset)
        What to do when there is no initial offset in Kafka or if the current offset does not exist any more on the server (e.g. because that data has been deleted):
        • earliest: automatically reset the offset to the earliest offset
        • latest: automatically reset the offset to the latest offset
        • none: throw exception to the consumer if no previous offset is found for the consumer's group
        • Type: string
        • Default: latest
        • Valid Values: [latest, earliest, none]

        Parameters:
        autoOffsetReset - [latest, earliest, none]
        Returns:
        this builder
      • batchSize

        public KafkaConfigBuilder batchSize​(int batchSize)
        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. This configuration controls the default batch size in bytes. 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.
        • Type: int
        • Default: 16384
        Parameters:
        batchSize - batch size in bytes
        Returns:
        this builder
      • acks

        public KafkaConfigBuilder acks​(String acks)
        The number of acknowledgments the 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:

        • acks=0 If set to zero then the 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.
        • acks=1 This will mean 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.
        • acks=all This means 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. This is equivalent to the acks=-1 setting.
        • Type: string
        • Default: 1
        • Valid Values: [all, -1, 0, 1]
        Parameters:
        acks - acknowledge mode
        Returns:
        this builder
      • bufferMemory

        public KafkaConfigBuilder bufferMemory​(long bufferMemory)
        The total bytes of memory the 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 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.
        • Type: long
        • Default: 33554432
        Parameters:
        bufferMemory - bytes of memory
        Returns:
        this builder
      • compressionType

        public KafkaConfigBuilder compressionType​(String compressionType)
        The compression type for all data generated by the producer. The default is none (i.e. no compression). Valid values are none, gzip, snappy, lz4, or zstd. Compression is of full batches of data, so the efficacy of batching will also impact the compression ratio (more batching means better compression).
        • Type: string
        • Default: none
        • Valid Values: [none, gzip, snappy, lz4, zstd]
        Parameters:
        compressionType - compression type
        Returns:
        this builder
      • retries

        public KafkaConfigBuilder retries​(int retries)
        Setting a value greater than zero 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 additionally 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.
        • Type: int
        • Default: 2147483647
        Parameters:
        retries - number of retries
        Returns:
        this builder