public class ContainerProperties
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
ContainerProperties.AckMode
The offset commit behavior enumeration.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_MONITOR_INTERVAL
The default
monitorInterval (s). |
static float |
DEFAULT_NO_POLL_THRESHOLD
The default
noPollThreshold. |
static long |
DEFAULT_POLL_TIMEOUT
The default
pollTimeout (ms). |
static long |
DEFAULT_SHUTDOWN_TIMEOUT
The default
shutDownTimeout (ms). |
| Constructor and Description |
|---|
ContainerProperties(java.util.regex.Pattern topicPattern)
Create properties for a container that will subscribe to topics matching the
specified pattern.
|
ContainerProperties(java.lang.String... topics)
Create properties for a container that will subscribe to the specified topics.
|
ContainerProperties(TopicPartitionInitialOffset... topicPartitions)
Create properties for a container that will assign itself the provided topic
partitions.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getAckCount() |
ContainerProperties.AckMode |
getAckMode() |
long |
getAckTime() |
java.lang.String |
getClientId()
Return the client id.
|
org.apache.kafka.clients.consumer.OffsetCommitCallback |
getCommitCallback() |
LogIfLevelEnabled.Level |
getCommitLogLevel()
The level at which to log offset commits.
|
java.util.Properties |
getConsumerProperties()
Get the consumer properties that will be merged with the consumer properties
provided by the consumer factory; properties here will supersede any with the same
name(s) in the consumer factory.
|
org.apache.kafka.clients.consumer.ConsumerRebalanceListener |
getConsumerRebalanceListener() |
org.springframework.core.task.AsyncListenableTaskExecutor |
getConsumerTaskExecutor() |
java.lang.String |
getGroupId() |
java.lang.Long |
getIdleEventInterval() |
java.lang.Object |
getMessageListener() |
int |
getMonitorInterval() |
float |
getNoPollThreshold() |
long |
getPollTimeout() |
org.springframework.scheduling.TaskScheduler |
getScheduler() |
long |
getShutdownTimeout() |
TopicPartitionInitialOffset[] |
getTopicPartitions() |
java.util.regex.Pattern |
getTopicPattern() |
java.lang.String[] |
getTopics() |
org.springframework.transaction.PlatformTransactionManager |
getTransactionManager() |
boolean |
isAckOnError() |
boolean |
isLogContainerConfig()
Log the container configuration if true (INFO).
|
boolean |
isMissingTopicsFatal()
If true, the container won't start if any of the configured topics are not present
on the broker.
|
boolean |
isSyncCommits() |
void |
setAckCount(int count)
Set the number of outstanding record count after which offsets should be
committed when
ContainerProperties.AckMode.COUNT or ContainerProperties.AckMode.COUNT_TIME is being used. |
void |
setAckMode(ContainerProperties.AckMode ackMode)
Set the ack mode to use when auto ack (in the configuration properties) is false.
|
void |
setAckOnError(boolean ackOnError)
Set whether or not the container should commit offsets (ack messages) where the
listener throws exceptions.
|
void |
setAckTime(long ackTime)
Set the time (ms) after which outstanding offsets should be committed when
ContainerProperties.AckMode.TIME or ContainerProperties.AckMode.COUNT_TIME is being used. |
void |
setClientId(java.lang.String clientId)
Set the client id; overrides the consumer factory client.id property.
|
void |
setCommitCallback(org.apache.kafka.clients.consumer.OffsetCommitCallback commitCallback)
Set the commit callback; by default a simple logging callback is used to log
success at DEBUG level and failures at ERROR level.
|
void |
setCommitLogLevel(LogIfLevelEnabled.Level commitLogLevel)
Set the level at which to log offset commits.
|
void |
setConsumerProperties(java.util.Properties consumerProperties)
Set the consumer properties that will be merged with the consumer properties
provided by the consumer factory; properties here will supersede any with the same
name(s) in the consumer factory.
|
void |
setConsumerRebalanceListener(org.apache.kafka.clients.consumer.ConsumerRebalanceListener consumerRebalanceListener)
Set the user defined
ConsumerRebalanceListener implementation. |
void |
setConsumerTaskExecutor(org.springframework.core.task.AsyncListenableTaskExecutor consumerTaskExecutor)
Set the executor for threads that poll the consumer.
|
void |
setGroupId(java.lang.String groupId)
Set the group id for this container.
|
void |
setIdleEventInterval(java.lang.Long idleEventInterval)
Set the idle event interval; when set, an event is emitted if a poll returns
no records and this interval has elapsed since a record was returned.
|
void |
setLogContainerConfig(boolean logContainerConfig)
Set to true to instruct each container to log this configuration.
|
void |
setMessageListener(java.lang.Object messageListener)
Set the message listener; must be a
MessageListener
or AcknowledgingMessageListener. |
void |
setMissingTopicsFatal(boolean missingTopicsFatal)
Set to false to allow the container to start even if any of the configured topics
are not present on the broker.
|
void |
setMonitorInterval(int monitorInterval)
The interval between checks for a non-responsive consumer in
seconds; default 30.
|
void |
setNoPollThreshold(float noPollThreshold)
If the time since the last poll /
poll timeout
exceeds this value, a NonResponsiveConsumerEvent is published. |
void |
setPollTimeout(long pollTimeout)
Set the max time to block in the consumer waiting for records.
|
void |
setScheduler(org.springframework.scheduling.TaskScheduler scheduler)
A scheduler used with the monitor interval.
|
void |
setShutdownTimeout(long shutdownTimeout)
Set the timeout for shutting down the container.
|
void |
setSyncCommits(boolean syncCommits)
Set whether or not to call consumer.commitSync() or commitAsync() when the
container is responsible for commits.
|
void |
setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)
Set the transaction manager to start a transaction; only
ContainerProperties.AckMode.RECORD and
ContainerProperties.AckMode.BATCH (default) are supported with transactions. |
java.lang.String |
toString() |
public static final long DEFAULT_POLL_TIMEOUT
pollTimeout (ms).public static final long DEFAULT_SHUTDOWN_TIMEOUT
shutDownTimeout (ms).public static final int DEFAULT_MONITOR_INTERVAL
monitorInterval (s).public static final float DEFAULT_NO_POLL_THRESHOLD
noPollThreshold.public ContainerProperties(java.lang.String... topics)
topics - the topics.public ContainerProperties(java.util.regex.Pattern topicPattern)
topicPattern - the pattern.CommonClientConfigs.METADATA_MAX_AGE_CONFIGpublic ContainerProperties(TopicPartitionInitialOffset... topicPartitions)
topicPartitions - the topic partitions.public void setMessageListener(java.lang.Object messageListener)
MessageListener
or AcknowledgingMessageListener.messageListener - the listener.public void setAckMode(ContainerProperties.AckMode ackMode)
#setPollTimeout(long) pollTimeout.AcknowledgingMessageListener.
ackMode - the ContainerProperties.AckMode; default BATCH.public void setPollTimeout(long pollTimeout)
pollTimeout - the timeout in ms; default 5000L.public void setAckCount(int count)
ContainerProperties.AckMode.COUNT or ContainerProperties.AckMode.COUNT_TIME is being used.count - the countpublic void setAckTime(long ackTime)
ContainerProperties.AckMode.TIME or ContainerProperties.AckMode.COUNT_TIME is being used. Should be
larger thanackTime - the timepublic void setConsumerTaskExecutor(org.springframework.core.task.AsyncListenableTaskExecutor consumerTaskExecutor)
consumerTaskExecutor - the executorpublic void setShutdownTimeout(long shutdownTimeout)
#stop(Runnable) will block for, before
returning; default 10000L.shutdownTimeout - the shutdown timeout.public void setConsumerRebalanceListener(org.apache.kafka.clients.consumer.ConsumerRebalanceListener consumerRebalanceListener)
ConsumerRebalanceListener implementation.consumerRebalanceListener - the ConsumerRebalanceListener instancepublic void setCommitCallback(org.apache.kafka.clients.consumer.OffsetCommitCallback commitCallback)
syncCommits is false.commitCallback - the callback.setSyncCommits(boolean)public void setSyncCommits(boolean syncCommits)
syncCommits - true to use commitSync().setCommitCallback(OffsetCommitCallback),
setCommitLogLevel(org.springframework.kafka.support.LogIfLevelEnabled.Level)public void setIdleEventInterval(java.lang.Long idleEventInterval)
idleEventInterval - the interval.public void setAckOnError(boolean ackOnError)
ackMode and is
effective only when the kafka property enable.auto.commit is false;
it is not applicable to manual ack modes. When this property is set to true
(the default), all messages handled will have their offset committed. When set to
false, offsets will be committed only for successfully handled messages.
Manual acks will always be applied. Bear in mind that, if the next message is
successfully handled, its offset will be committed, effectively committing the
offset of the failed message anyway, so this option has limited applicability.
Perhaps useful for a component that starts throwing exceptions consistently;
allowing it to resume when restarted from the last successfully processed message.
Does not apply when transactions are used - in that case, whether or not the offsets are sent to the transaction depends on whether the transaction is committed or rolled back. If a listener throws an exception, the transaction will normally be rolled back unless an error handler is provided that handles the error and exits normally; in which case the offsets are sent to the transaction and the transaction is committed.
ackOnError - whether the container should acknowledge messages that throw
exceptions.public void setGroupId(java.lang.String groupId)
group.id property
provided by the consumer factory configuration.groupId - the group id.public java.lang.String[] getTopics()
public java.util.regex.Pattern getTopicPattern()
public TopicPartitionInitialOffset[] getTopicPartitions()
public ContainerProperties.AckMode getAckMode()
public int getAckCount()
public long getAckTime()
public java.lang.Object getMessageListener()
public long getPollTimeout()
public org.springframework.core.task.AsyncListenableTaskExecutor getConsumerTaskExecutor()
public long getShutdownTimeout()
public org.apache.kafka.clients.consumer.ConsumerRebalanceListener getConsumerRebalanceListener()
public org.apache.kafka.clients.consumer.OffsetCommitCallback getCommitCallback()
public boolean isSyncCommits()
public java.lang.Long getIdleEventInterval()
public boolean isAckOnError()
public java.lang.String getGroupId()
public org.springframework.transaction.PlatformTransactionManager getTransactionManager()
public void setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)
ContainerProperties.AckMode.RECORD and
ContainerProperties.AckMode.BATCH (default) are supported with transactions.transactionManager - the transaction manager.public int getMonitorInterval()
public void setMonitorInterval(int monitorInterval)
monitorInterval - the interval.public org.springframework.scheduling.TaskScheduler getScheduler()
public void setScheduler(org.springframework.scheduling.TaskScheduler scheduler)
scheduler - the scheduler.setMonitorInterval(int)public float getNoPollThreshold()
public void setNoPollThreshold(float noPollThreshold)
poll timeout
exceeds this value, a NonResponsiveConsumerEvent is published.
Default 3.0f.noPollThreshold - the thresholdpublic java.lang.String getClientId()
setClientId(String)public void setClientId(java.lang.String clientId)
clientId - the client id.public boolean isLogContainerConfig()
public void setLogContainerConfig(boolean logContainerConfig)
logContainerConfig - true to log.public LogIfLevelEnabled.Level getCommitLogLevel()
public void setCommitLogLevel(LogIfLevelEnabled.Level commitLogLevel)
commitLogLevel - the level.public boolean isMissingTopicsFatal()
public void setMissingTopicsFatal(boolean missingTopicsFatal)
missingTopicsFatal - the missingTopicsFatal.@Nullable public java.util.Properties getConsumerProperties()
group.id and client.id are ignored.ConsumerConfig,
setGroupId(String),
setClientId(String)public void setConsumerProperties(java.util.Properties consumerProperties)
group.id and client.id are ignored.consumerProperties - the properties.ConsumerConfig,
setGroupId(String),
setClientId(String)public java.lang.String toString()
toString in class java.lang.Object