Class KafkaPublisher.Builder<K,V>
java.lang.Object
io.helidon.messaging.connectors.kafka.KafkaPublisher.Builder<K,V>
- Type Parameters:
K
- Key typeV
- Value type
- All Implemented Interfaces:
Builder<KafkaPublisher.Builder<K,
,V>, KafkaPublisher<K, V>> Supplier<KafkaPublisher<K,
V>>
- Enclosing class:
KafkaPublisher<K,
V>
public static final class KafkaPublisher.Builder<K,V>
extends Object
implements Builder<KafkaPublisher.Builder<K,V>,KafkaPublisher<K,V>>
Fluent API builder for
KafkaPublisher
.-
Method Summary
Modifier and TypeMethodDescriptionackTimeout
(long ackTimeout) This value applies only when autoCommit is set to false.autoCommit
(boolean autoCommit) This flag defines the strategy of committing messages to Kafka.build()
Build the instance from this builder.Load this builder from a configuration.consumerSupplier
(Supplier<org.apache.kafka.clients.consumer.Consumer<K, V>> consumerSupplier) Defines how to instantiate the KafkaConsumer.limitNoAck
(int limitNoAck) This value applies only when autoCommit is set to false.periodExecutions
(long periodExecutions) Specifies the period in milliseconds between successive scheduler executions.pollTimeout
(long pollTimeout) Specifies maximum time in milliseconds to block polling messages from Kafka.scheduler
(ScheduledExecutorService scheduler) Specify a scheduler that will read ad process messages coming from Kafka.topicPattern
(Pattern topicPattern) The pattern for selecting multiple topics.The list of topics to subscribe to.
-
Method Details
-
config
Load this builder from a configuration.- Parameters:
config
- configuration to load from- Returns:
- updated builder instance
-
consumerSupplier
public KafkaPublisher.Builder<K,V> consumerSupplier(Supplier<org.apache.kafka.clients.consumer.Consumer<K, V>> consumerSupplier) Defines how to instantiate the KafkaConsumer. It will be invoked inKafkaPublisher.subscribe(Subscriber)
This is a mandatory parameter.- Parameters:
consumerSupplier
- instantiated Kafka consumer- Returns:
- updated builder instance
-
topics
The list of topics to subscribe to. This is a mandatory parameter if topicPattern is empty.- Parameters:
topics
- list of topics to subscribe to- Returns:
- updated builder instance
-
topicPattern
The pattern for selecting multiple topics. This is a mandatory parameter if topics is empty.- Parameters:
topicPattern
- pattern for selecting multiple topics- Returns:
- updated builder instance
-
scheduler
Specify a scheduler that will read ad process messages coming from Kafka. Is it intended that this scheduler is reused for other tasks. This is a mandatory parameter.- Parameters:
scheduler
- scheduler that will read ad process messages- Returns:
- updated builder instance
-
periodExecutions
Specifies the period in milliseconds between successive scheduler executions. The default value is 100 milliseconds.- Parameters:
periodExecutions
- period in milliseconds- Returns:
- updated builder instance
-
pollTimeout
Specifies maximum time in milliseconds to block polling messages from Kafka. The default value is 50 milliseconds.- Parameters:
pollTimeout
- maximum time in milliseconds to block polling- Returns:
- updated builder instance
-
autoCommit
This flag defines the strategy of committing messages to Kafka. When true, the messages are committed at the moment they are polled from Kafka. When false, the messages are committed whenMessage.ack()
is invoked. This value is mandatory to be specified, and it must be consistent with the value enable.auto.commit in Kafka properties. Failing to do this will result the next scenarios: - For autoCommit = true and enable.auto.commit = false, messages will never be committed in Kafka. - For autoCommit = false and enable.auto.commit = true, all messages will be committed andMessage.ack()
will have no effect.- Parameters:
autoCommit
- strategy of committing- Returns:
- updated builder instance
-
ackTimeout
This value applies only when autoCommit is set to false. It defines the maximum time in milliseconds thatMessage.ack()
will be waiting for the commit in Kafka. The default value is Long.MAX_VALUE- Parameters:
ackTimeout
- time in milliseconds- Returns:
- updated builder instance
-
limitNoAck
This value applies only when autoCommit is set to false. It specifies the limit of messages waiting to be committed in Kafka. If this value is overflown, the KafkaPublisher will notify a failure. The intention of this value is to fail gracefully when there are many pending commits, instead of failing with OutOfMemoryError.- Parameters:
limitNoAck
- limit of messages waiting to be committed- Returns:
- updated builder instance
-
build
Description copied from interface:Builder
Build the instance from this builder.
-