public class ReceiverOptions<K,V>
extends java.lang.Object
KafkaReceiver and its underlying KafkaConsumer.| Modifier and Type | Method and Description |
|---|---|
ReceiverOptions<K,V> |
addAssignListener(java.util.function.Consumer<java.util.Collection<ReceiverPartition>> onAssign)
Adds a listener for partition assignments.
|
ReceiverOptions<K,V> |
addRevokeListener(java.util.function.Consumer<java.util.Collection<ReceiverPartition>> onRevoke)
Adds a listener for partition revocations.
|
java.util.List<java.util.function.Consumer<java.util.Collection<ReceiverPartition>>> |
assignListeners()
Returns list of configured partition assignment listeners.
|
java.util.Collection<TopicPartition> |
assignment()
Returns the collection of partitions to be assigned if this instance is
configured for manual partition assignment.
|
ReceiverOptions<K,V> |
assignment(java.util.Collection<TopicPartition> partitions)
Sets subscription using manual assignment to the specified partitions.
|
int |
atmostOnceCommitAheadSize()
Returns the maximum difference between the offset committed for at-most-once
delivery and the offset of the last record dispatched.
|
ReceiverOptions<K,V> |
atmostOnceCommitAheadSize(int commitAheadSize)
Configures commit ahead size per partition for at-most-once delivery.
|
ReceiverOptions<K,V> |
clearAssignListeners()
Removes all partition assignment listeners.
|
ReceiverOptions<K,V> |
clearRevokeListeners()
Removes all partition revocation listeners.
|
java.time.Duration |
closeTimeout()
Returns timeout for graceful shutdown of
KafkaConsumer. |
ReceiverOptions<K,V> |
closeTimeout(java.time.Duration timeout)
Sets timeout for graceful shutdown of
KafkaConsumer. |
int |
commitBatchSize()
Returns the configured commit batch size for automatic commits of acknowledged records.
|
ReceiverOptions<K,V> |
commitBatchSize(int commitBatchSize)
Configures commit batch size for automatic commits.
|
java.time.Duration |
commitInterval()
Returns the configured commit interval for automatic commits of acknowledged records.
|
ReceiverOptions<K,V> |
commitInterval(java.time.Duration commitInterval)
Configures commit interval for automatic commits.
|
java.util.Map<java.lang.String,java.lang.Object> |
consumerProperties()
Returns the configuration properties of the underlying
KafkaConsumer. |
java.lang.Object |
consumerProperty(java.lang.String name)
Returns the
KafkaConsumer configuration property value for the specified option name. |
ReceiverOptions<K,V> |
consumerProperty(java.lang.String name,
java.lang.Object newValue)
Sets
KafkaConsumer configuration property to the specified value. |
static <K,V> ReceiverOptions<K,V> |
create()
Creates an options instance with default properties.
|
static <K,V> ReceiverOptions<K,V> |
create(java.util.Map<java.lang.String,java.lang.Object> configProperties)
Creates an options instance with the specified config overrides for
KafkaConsumer. |
static <K,V> ReceiverOptions<K,V> |
create(java.util.Properties configProperties)
Creates an options instance with the specified config overrides for
KafkaConsumer. |
java.lang.String |
groupId()
Returns the configured Kafka consumer group id.
|
java.time.Duration |
heartbeatInterval()
Returns the configured heartbeat interval for Kafka consumer.
|
java.util.Optional<Deserializer<K>> |
keyDeserializer()
Returns optionally a deserializer witch is used by
KafkaConsumer for key deserialization. |
int |
maxCommitAttempts()
Returns the maximum number of consecutive non-fatal commit failures that are tolerated.
|
ReceiverOptions<K,V> |
maxCommitAttempts(int maxAttempts)
Configures the maximum number of consecutive non-fatal
RetriableCommitFailedException
commit failures that are tolerated. |
java.time.Duration |
pollTimeout()
Returns the timeout for each
KafkaConsumer.poll(long) operation. |
ReceiverOptions<K,V> |
pollTimeout(java.time.Duration timeout)
Sets the timeout for each
KafkaConsumer.poll(long) operation. |
java.util.List<java.util.function.Consumer<java.util.Collection<ReceiverPartition>>> |
revokeListeners()
Returns list of configured partition revocation listeners.
|
java.util.function.Consumer<Consumer<K,V>> |
subscriber(ConsumerRebalanceListener listener)
Returns the
KafkaConsumer.subscribe(Collection, ConsumerRebalanceListener),
KafkaConsumer.subscribe(Pattern, ConsumerRebalanceListener) or KafkaConsumer.assign(Collection)
operation corresponding to the subscription or assignment options configured for this instance. |
ReceiverOptions<K,V> |
subscription(java.util.Collection<java.lang.String> topics)
Sets subscription using group management to the specified collection of topics.
|
ReceiverOptions<K,V> |
subscription(java.util.regex.Pattern pattern)
Sets subscription using group management to the specified pattern.
|
ReceiverOptions<K,V> |
toImmutable()
Returns a new immutable instance with the configuration properties of this instance.
|
java.util.Optional<Deserializer<V>> |
valueDeserializer()
Returns optionally a deserializer witch is used by
KafkaConsumer for value deserialization. |
ReceiverOptions<K,V> |
withKeyDeserializer(Deserializer<K> keyDeserializer)
Set a concrete deserializer instant to be used by the
KafkaConsumer for keys. |
ReceiverOptions<K,V> |
withValueDeserializer(Deserializer<V> valueDeserializer)
Set a concrete deserializer instant to be used by the
KafkaConsumer for values. |
public static <K,V> ReceiverOptions<K,V> create()
public static <K,V> ReceiverOptions<K,V> create(java.util.Map<java.lang.String,java.lang.Object> configProperties)
KafkaConsumer.public static <K,V> ReceiverOptions<K,V> create(java.util.Properties configProperties)
KafkaConsumer.public java.util.Map<java.lang.String,java.lang.Object> consumerProperties()
KafkaConsumer.public java.lang.Object consumerProperty(java.lang.String name)
KafkaConsumer configuration property value for the specified option name.public ReceiverOptions<K,V> consumerProperty(java.lang.String name, java.lang.Object newValue)
KafkaConsumer configuration property to the specified value.public ReceiverOptions<K,V> withKeyDeserializer(Deserializer<K> keyDeserializer)
KafkaConsumer for keys. Overrides any setting of the
ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG property.keyDeserializer - key deserializer to use in the consumerpublic java.util.Optional<Deserializer<K>> keyDeserializer()
KafkaConsumer for key deserialization.public ReceiverOptions<K,V> withValueDeserializer(Deserializer<V> valueDeserializer)
KafkaConsumer for values. Overrides any setting of the
ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG property.valueDeserializer - value deserializer to use in the consumerpublic java.util.Optional<Deserializer<V>> valueDeserializer()
KafkaConsumer for value deserialization.public java.time.Duration pollTimeout()
KafkaConsumer.poll(long) operation.public ReceiverOptions<K,V> pollTimeout(java.time.Duration timeout)
KafkaConsumer.poll(long) operation. Since
the underlying Kafka consumer is not thread-safe, long poll intervals may delay
commits and other operations invoked using KafkaReceiver.doOnConsumer(java.util.function.Function).
Very short timeouts may reduce batching and increase load on the broker,public java.time.Duration closeTimeout()
KafkaConsumer.public ReceiverOptions<K,V> closeTimeout(java.time.Duration timeout)
KafkaConsumer.public ReceiverOptions<K,V> addAssignListener(java.util.function.Consumer<java.util.Collection<ReceiverPartition>> onAssign)
ReceiverPartition. When group management is used, assign listeners are invoked
after every rebalance operation. With manual partition assignment using assignment(),
assign listeners are invoked once when the receive Flux is subscribed to.public ReceiverOptions<K,V> addRevokeListener(java.util.function.Consumer<java.util.Collection<ReceiverPartition>> onRevoke)
assignment(),
revoke listeners are invoked once when the receive Flux is terminated.public ReceiverOptions<K,V> clearAssignListeners()
public ReceiverOptions<K,V> clearRevokeListeners()
public java.util.List<java.util.function.Consumer<java.util.Collection<ReceiverPartition>>> assignListeners()
public java.util.List<java.util.function.Consumer<java.util.Collection<ReceiverPartition>>> revokeListeners()
public ReceiverOptions<K,V> subscription(java.util.Collection<java.lang.String> topics)
KafkaReceiver using this
options instance is subscribed to. Any existing subscriptions or assignments on this
option are deleted.public ReceiverOptions<K,V> subscription(java.util.regex.Pattern pattern)
KafkaReceiver using this
options instance is subscribed to. Any existing subscriptions or assignments on this
option are deleted. Topics are dynamically assigned or removed when topics
matching the pattern are created or deleted.public ReceiverOptions<K,V> assignment(java.util.Collection<TopicPartition> partitions)
KafkaReceiver using this
options instance is subscribed to. Any existing subscriptions or assignments on this
option are deleted.public java.util.Collection<TopicPartition> assignment()
public java.util.function.Consumer<Consumer<K,V>> subscriber(ConsumerRebalanceListener listener)
KafkaConsumer.subscribe(Collection, ConsumerRebalanceListener),
KafkaConsumer.subscribe(Pattern, ConsumerRebalanceListener) or KafkaConsumer.assign(Collection)
operation corresponding to the subscription or assignment options configured for this instance.public java.lang.String groupId()
public java.time.Duration heartbeatInterval()
public java.time.Duration commitInterval()
public ReceiverOptions<K,V> commitInterval(java.time.Duration commitInterval)
If commitInterval is zero, periodic commits based on time intervals
are disabled. If commit batch size is configured, offsets are committed when the number
of acknowledged offsets reaches the batch size. If commit batch size is also zero, it
is the responsibility of the application to explicitly commit records using
ReceiverOffset.commit() if required.
If commit interval and commit batch size are configured, a commit operation is scheduled when either the interval or batch size is reached.
public int commitBatchSize()
public ReceiverOptions<K,V> commitBatchSize(int commitBatchSize)
If commitBatchSize is 0, commits are only performed based on commit
interval. If commit interval is null, no automatic commits are performed and it is the
responsibility of the application to commit offsets explicitly using ReceiverOffset.commit()
if required.
If commit batch size and commit interval are configured, a commit operation is scheduled when either the batch size or interval is reached.
public int atmostOnceCommitAheadSize()
commitAheadSize + 1public ReceiverOptions<K,V> atmostOnceCommitAheadSize(int commitAheadSize)
commitAheadSize + 1.
A high commit ahead size reduces the cost of commits in at-most-once delivery by
reducing the number of commits and avoiding blocking before dispatch if the offset
corresponding to the record was already committed.
If commitAheadSize is zero (default), offsets are committed synchronously before
each record is dispatched for KafkaReceiver.receiveAtmostOnce(). Otherwise, commits are
performed ahead of dispatch and record dispatch is blocked only if commits haven't completed.
public int maxCommitAttempts()
public ReceiverOptions<K,V> maxCommitAttempts(int maxAttempts)
RetriableCommitFailedException
commit failures that are tolerated. For manual commits, failure in commit after the configured
number of attempts fails the commit operation. For auto commits, the receive Flux is terminated
if the commit does not succeed after these attempts.public ReceiverOptions<K,V> toImmutable()