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<K,V>>
,Supplier<KafkaPublisher<K,V>>
- Enclosing class:
- KafkaPublisher<K,V>
public static final class KafkaPublisher.Builder<K,V> extends Object implements Builder<KafkaPublisher<K,V>>
Fluent API builder forKafkaPublisher
.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description KafkaPublisher.Builder<K,V>
ackTimeout(long ackTimeout)
This value applies only when autoCommit is set to false.KafkaPublisher.Builder<K,V>
autoCommit(boolean autoCommit)
This flag defines the strategy of committing messages to Kafka.KafkaPublisher<K,V>
build()
Build the instance from this builder.KafkaPublisher.Builder<K,V>
config(Config config)
Load this builder from a configuration.KafkaPublisher.Builder<K,V>
consumerSupplier(Supplier<org.apache.kafka.clients.consumer.Consumer<K,V>> consumerSupplier)
Defines how to instantiate the KafkaConsumer.KafkaPublisher.Builder<K,V>
limitNoAck(int limitNoAck)
This value applies only when autoCommit is set to false.KafkaPublisher.Builder<K,V>
periodExecutions(long periodExecutions)
Specifies the period in milliseconds between successive scheduler executions.KafkaPublisher.Builder<K,V>
pollTimeout(long pollTimeout)
Specifies maximum time in milliseconds to block polling messages from Kafka.KafkaPublisher.Builder<K,V>
scheduler(ScheduledExecutorService scheduler)
Specify a scheduler that will read ad process messages coming from Kafka.KafkaPublisher.Builder<K,V>
topicPattern(Pattern topicPattern)
The pattern for selecting multiple topics.KafkaPublisher.Builder<K,V>
topics(List<String> topics)
The list of topics to subscribe to.
-
-
-
Method Detail
-
config
public KafkaPublisher.Builder<K,V> config(Config 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
public KafkaPublisher.Builder<K,V> topics(List<String> 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
public KafkaPublisher.Builder<K,V> topicPattern(Pattern 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
public KafkaPublisher.Builder<K,V> scheduler(ScheduledExecutorService 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
public KafkaPublisher.Builder<K,V> periodExecutions(long 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
public KafkaPublisher.Builder<K,V> pollTimeout(long 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
public KafkaPublisher.Builder<K,V> autoCommit(boolean 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
public KafkaPublisher.Builder<K,V> ackTimeout(long 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
public KafkaPublisher.Builder<K,V> limitNoAck(int 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
-
-