Class AbstractShareKafkaMessageListenerContainer<K,V>
java.lang.Object
org.springframework.kafka.listener.AbstractShareKafkaMessageListenerContainer<K,V>
- Type Parameters:
K- the key typeV- 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
- Direct Known Subclasses:
ShareKafkaMessageListenerContainer
public abstract class AbstractShareKafkaMessageListenerContainer<K,V>
extends Object
implements GenericMessageListenerContainer<K,V>, org.springframework.beans.factory.BeanNameAware, org.springframework.context.ApplicationEventPublisherAware, org.springframework.context.ApplicationContextAware
Abstract base class for share consumer message listener containers.
Handles common lifecycle, configuration, and event publishing for containers using a
ShareConsumerFactory.
Subclasses are responsible for implementing the actual consumer loop and message dispatch logic.
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe defaultSmartLifecyclephase for listener containers.protected final ReentrantLockprotected final org.springframework.core.log.LogAccessorprotected final ShareConsumerFactory<K, V> The share consumer factory used to create consumer instances. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractShareKafkaMessageListenerContainer(ShareConsumerFactory<? super K, ? super V> shareConsumerFactory, ContainerProperties containerProperties) Construct an instance with the provided factory and properties. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()protected abstract voiddoStart()protected abstract voiddoStop()@Nullable org.springframework.context.ApplicationContext@Nullable org.springframework.context.ApplicationEventPublisherGet the event publisher.Return the bean name.Return the container properties for this container.@Nullable StringReturn thegroup.idproperty for this container whether specifically set on the container or via a consumer property on the consumer factory.The 'id' attribute of a@KafkaListeneror the bean name for spring-managed containers.intgetPhase()booleanbooleanvoidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) voidsetApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher) voidsetAutoStartup(boolean autoStartup) Set the autoStartup.voidsetBeanName(String name) voidsetPhase(int phase) protected voidsetRunning(boolean running) voidsetupMessageListener(Object messageListener) Setup the message listener to use.voidstart()voidstop()voidMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface MessageListenerContainer
childStarted, childStopped, enforceRebalance, getAssignedPartitions, getAssignmentsByClientId, getContainerFor, getListenerInfo, getMainListenerId, isChildRunning, isContainerPaused, isInExpectedState, isPartitionPaused, isPartitionPauseRequested, isPauseRequested, metrics, pause, pausePartition, resume, resumePartition, stopAbnormallyMethods inherited from interface org.springframework.context.SmartLifecycle
isPauseable
-
Field Details
-
DEFAULT_PHASE
public static final int DEFAULT_PHASEThe defaultSmartLifecyclephase for listener containers.- See Also:
-
logger
protected final org.springframework.core.log.LogAccessor logger -
lifecycleLock
-
-
Constructor Details
-
Method Details
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
getApplicationContext
public @Nullable org.springframework.context.ApplicationContext getApplicationContext() -
setBeanName
- Specified by:
setBeanNamein interfaceorg.springframework.beans.factory.BeanNameAware
-
getBeanName
-
setApplicationEventPublisher
public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher) - Specified by:
setApplicationEventPublisherin interfaceorg.springframework.context.ApplicationEventPublisherAware
-
getApplicationEventPublisher
public @Nullable org.springframework.context.ApplicationEventPublisher getApplicationEventPublisher()Get the event publisher.- Returns:
- the publisher
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartupin interfaceorg.springframework.context.SmartLifecycle
-
setAutoStartup
public void setAutoStartup(boolean autoStartup) Description copied from interface:MessageListenerContainerSet the autoStartup.- Specified by:
setAutoStartupin interfaceMessageListenerContainer- Parameters:
autoStartup- the autoStartup to set.- See Also:
-
getPhase
public int getPhase()- Specified by:
getPhasein interfaceorg.springframework.context.Phased- Specified by:
getPhasein interfaceorg.springframework.context.SmartLifecycle
-
setPhase
public void setPhase(int phase) -
stop
- Specified by:
stopin interfaceorg.springframework.context.SmartLifecycle
-
start
public void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
setRunning
protected void setRunning(boolean running) -
getContainerProperties
Description copied from interface:MessageListenerContainerReturn the container properties for this container.- Specified by:
getContainerPropertiesin interfaceMessageListenerContainer- Returns:
- the properties.
-
getGroupId
Description copied from interface:MessageListenerContainerReturn thegroup.idproperty for this container whether specifically set on the container or via a consumer property on the consumer factory.- Specified by:
getGroupIdin interfaceMessageListenerContainer- Returns:
- the group id.
-
getListenerId
Description copied from interface:MessageListenerContainerThe 'id' attribute of a@KafkaListeneror the bean name for spring-managed containers.- Specified by:
getListenerIdin interfaceMessageListenerContainer- Returns:
- the id or bean name.
-
setupMessageListener
Description copied from interface:MessageListenerContainerSetup the message listener to use. Throws anIllegalArgumentExceptionif that message listener type is not supported.- Specified by:
setupMessageListenerin interfaceMessageListenerContainer- Parameters:
messageListener- theobjectto wrapped to theMessageListener.
-
doStart
protected abstract void doStart() -
doStop
protected abstract void doStop() -
destroy
public void destroy()- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean- Specified by:
destroyin interfaceMessageListenerContainer
-