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:
Aware,BeanNameAware,DisposableBean,ApplicationContextAware,ApplicationEventPublisherAware,Lifecycle,Phased,SmartLifecycle,GenericMessageListenerContainer<K,,V> MessageListenerContainer
- Direct Known Subclasses:
ShareKafkaMessageListenerContainer
public abstract class AbstractShareKafkaMessageListenerContainer<K,V>
extends Object
implements GenericMessageListenerContainer<K,V>, BeanNameAware, ApplicationEventPublisherAware, 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
- Author:
- Soby Chacko
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe defaultSmartLifecyclephase for listener containers.protected final ReentrantLockprotected final 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 ApplicationContext@Nullable 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(ApplicationContext applicationContext) voidsetApplicationEventPublisher(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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.kafka.listener.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
-
lifecycleLock
-
-
Constructor Details
-
Method Details
-
setApplicationContext
- Specified by:
setApplicationContextin interfaceApplicationContextAware- Throws:
BeansException
-
getApplicationContext
-
setBeanName
- Specified by:
setBeanNamein interfaceBeanNameAware
-
getBeanName
-
setApplicationEventPublisher
- Specified by:
setApplicationEventPublisherin interfaceApplicationEventPublisherAware
-
getApplicationEventPublisher
Get the event publisher.- Returns:
- the publisher
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartupin interfaceSmartLifecycle
-
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 interfacePhased- Specified by:
getPhasein interfaceSmartLifecycle
-
setPhase
public void setPhase(int phase) -
stop
- Specified by:
stopin interfaceSmartLifecycle
-
start
-
stop
-
isRunning
-
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 interfaceDisposableBean- Specified by:
destroyin interfaceMessageListenerContainer
-