Class KafkaMessageListenerContainer<K,V>
- java.lang.Object
-
- org.springframework.kafka.listener.AbstractMessageListenerContainer<K,V>
-
- org.springframework.kafka.listener.KafkaMessageListenerContainer<K,V>
-
- Type Parameters:
K- the key type.V- the value type.
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.DisposableBean,org.springframework.context.ApplicationContextAware,org.springframework.context.ApplicationEventPublisherAware,org.springframework.context.Lifecycle,org.springframework.context.Phased,org.springframework.context.SmartLifecycle,GenericMessageListenerContainer<K,V>,MessageListenerContainer
public class KafkaMessageListenerContainer<K,V> extends AbstractMessageListenerContainer<K,V>
Single-threaded Message listener container using the JavaConsumersupporting auto-partition assignment or user-configured assignment.With the latter, initial partition offsets can be provided.
-
-
Field Summary
-
Fields inherited from class org.springframework.kafka.listener.AbstractMessageListenerContainer
consumerFactory, DEFAULT_PHASE, lifecycleMonitor, logger
-
-
Constructor Summary
Constructors Constructor Description KafkaMessageListenerContainer(ConsumerFactory<? super K,? super V> consumerFactory, ContainerProperties containerProperties)Construct an instance with the supplied configuration properties.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoStart()protected voiddoStop(java.lang.Runnable callback)java.util.Collection<org.apache.kafka.common.TopicPartition>getAssignedPartitions()Return theTopicPartitions currently assigned to this container, either explicitly or by Kafka; may be null if not assigned yet.java.util.Map<java.lang.String,java.util.Collection<org.apache.kafka.common.TopicPartition>>getAssignmentsByClientId()Return the assigned topics/partitions for this container, by client.id.booleanisContainerPaused()Return true ifMessageListenerContainer.pause()has been called; and all consumers in this container have actually paused.java.util.Map<java.lang.String,java.util.Map<org.apache.kafka.common.MetricName,? extends org.apache.kafka.common.Metric>>metrics()Return metrics kept by this container's consumer(s), grouped byclient-id.protected AbstractMessageListenerContainer<?,?>parentOrThis()Return this or a parent container if this has a parent.voidsetClientIdSuffix(java.lang.String clientIdSuffix)Set a suffix to add to theclient.idconsumer property (if the consumer factory supports it).voidsetEmergencyStop(java.lang.Runnable emergencyStop)Set aRunnableto call whenever anErroroccurs on a listener thread.java.lang.StringtoString()-
Methods inherited from class org.springframework.kafka.listener.AbstractMessageListenerContainer
checkGroupId, checkTopics, createSimpleLoggingConsumerRebalanceListener, getAfterRollbackProcessor, getApplicationContext, getApplicationEventPublisher, getBatchInterceptor, getBeanName, getContainerProperties, getGenericErrorHandler, getGroupId, getListenerId, getPhase, getRecordInterceptor, isAutoStartup, isInterceptBeforeTx, isPaused, isPauseRequested, isRunning, pause, publishContainerStoppedEvent, resume, setAfterRollbackProcessor, setApplicationContext, setApplicationEventPublisher, setAutoStartup, setBatchErrorHandler, setBatchInterceptor, setBeanName, setErrorHandler, setGenericErrorHandler, setInterceptBeforeTx, setPhase, setRecordInterceptor, setRunning, setTopicCheckTimeout, setupMessageListener, start, stop, stop, stop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.springframework.kafka.listener.MessageListenerContainer
destroy
-
-
-
-
Constructor Detail
-
KafkaMessageListenerContainer
public KafkaMessageListenerContainer(ConsumerFactory<? super K,? super V> consumerFactory, ContainerProperties containerProperties)
Construct an instance with the supplied configuration properties.- Parameters:
consumerFactory- the consumer factory.containerProperties- the container properties.
-
-
Method Detail
-
setEmergencyStop
public void setEmergencyStop(java.lang.Runnable emergencyStop)
Set aRunnableto call whenever anErroroccurs on a listener thread.- Parameters:
emergencyStop- the Runnable.- Since:
- 2.2.1
-
setClientIdSuffix
public void setClientIdSuffix(java.lang.String clientIdSuffix)
Set a suffix to add to theclient.idconsumer property (if the consumer factory supports it).- Parameters:
clientIdSuffix- the suffix to add.- Since:
- 1.0.6
-
getAssignedPartitions
@Nullable public java.util.Collection<org.apache.kafka.common.TopicPartition> getAssignedPartitions()
Return theTopicPartitions currently assigned to this container, either explicitly or by Kafka; may be null if not assigned yet.- Returns:
- the
TopicPartitions currently assigned to this container, either explicitly or by Kafka; may be null if not assigned yet.
-
getAssignmentsByClientId
@Nullable public java.util.Map<java.lang.String,java.util.Collection<org.apache.kafka.common.TopicPartition>> getAssignmentsByClientId()
Description copied from interface:MessageListenerContainerReturn the assigned topics/partitions for this container, by client.id.- Returns:
- the topics/partitions.
-
isContainerPaused
public boolean isContainerPaused()
Description copied from interface:MessageListenerContainerReturn true ifMessageListenerContainer.pause()has been called; and all consumers in this container have actually paused.- Returns:
- true if the container is paused.
-
metrics
public java.util.Map<java.lang.String,java.util.Map<org.apache.kafka.common.MetricName,? extends org.apache.kafka.common.Metric>> metrics()
Description copied from interface:MessageListenerContainerReturn metrics kept by this container's consumer(s), grouped byclient-id.- Returns:
- the consumer(s) metrics grouped by
client-id - See Also:
Consumer.metrics()
-
doStart
protected void doStart()
- Specified by:
doStartin classAbstractMessageListenerContainer<K,V>
-
doStop
protected void doStop(java.lang.Runnable callback)
- Specified by:
doStopin classAbstractMessageListenerContainer<K,V>
-
parentOrThis
protected AbstractMessageListenerContainer<?,?> parentOrThis()
Description copied from class:AbstractMessageListenerContainerReturn this or a parent container if this has a parent.- Overrides:
parentOrThisin classAbstractMessageListenerContainer<K,V>- Returns:
- the parent or this.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-