Class AbstractShareKafkaMessageListenerContainer<K,V>

java.lang.Object
org.springframework.kafka.listener.AbstractShareKafkaMessageListenerContainer<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
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 Details

    • DEFAULT_PHASE

      public static final int DEFAULT_PHASE
      The default SmartLifecycle phase for listener containers.
      See Also:
    • shareConsumerFactory

      protected final ShareConsumerFactory<K,V> shareConsumerFactory
      The share consumer factory used to create consumer instances.
    • logger

      protected final org.springframework.core.log.LogAccessor logger
    • lifecycleLock

      protected final ReentrantLock lifecycleLock
  • Constructor Details

    • AbstractShareKafkaMessageListenerContainer

      protected AbstractShareKafkaMessageListenerContainer(ShareConsumerFactory<? super K, ? super V> shareConsumerFactory, ContainerProperties containerProperties)
      Construct an instance with the provided factory and properties.
      Parameters:
      shareConsumerFactory - the factory.
      containerProperties - the properties.
  • Method Details

    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException
    • getApplicationContext

      public @Nullable org.springframework.context.ApplicationContext getApplicationContext()
    • setBeanName

      public void setBeanName(String name)
      Specified by:
      setBeanName in interface org.springframework.beans.factory.BeanNameAware
    • getBeanName

      public String getBeanName()
      Return the bean name.
      Returns:
      the bean name
    • setApplicationEventPublisher

      public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
      Specified by:
      setApplicationEventPublisher in interface org.springframework.context.ApplicationEventPublisherAware
    • getApplicationEventPublisher

      public @Nullable org.springframework.context.ApplicationEventPublisher getApplicationEventPublisher()
      Get the event publisher.
      Returns:
      the publisher
    • isAutoStartup

      public boolean isAutoStartup()
      Specified by:
      isAutoStartup in interface org.springframework.context.SmartLifecycle
    • setAutoStartup

      public void setAutoStartup(boolean autoStartup)
      Description copied from interface: MessageListenerContainer
      Set the autoStartup.
      Specified by:
      setAutoStartup in interface MessageListenerContainer
      Parameters:
      autoStartup - the autoStartup to set.
      See Also:
      • SmartLifecycle
    • getPhase

      public int getPhase()
      Specified by:
      getPhase in interface org.springframework.context.Phased
      Specified by:
      getPhase in interface org.springframework.context.SmartLifecycle
    • setPhase

      public void setPhase(int phase)
    • stop

      public void stop(Runnable callback)
      Specified by:
      stop in interface org.springframework.context.SmartLifecycle
    • start

      public void start()
      Specified by:
      start in interface org.springframework.context.Lifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface org.springframework.context.Lifecycle
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
    • setRunning

      protected void setRunning(boolean running)
    • getContainerProperties

      public ContainerProperties getContainerProperties()
      Description copied from interface: MessageListenerContainer
      Return the container properties for this container.
      Specified by:
      getContainerProperties in interface MessageListenerContainer
      Returns:
      the properties.
    • getGroupId

      public @Nullable String getGroupId()
      Description copied from interface: MessageListenerContainer
      Return the group.id property for this container whether specifically set on the container or via a consumer property on the consumer factory.
      Specified by:
      getGroupId in interface MessageListenerContainer
      Returns:
      the group id.
    • getListenerId

      public String getListenerId()
      Description copied from interface: MessageListenerContainer
      The 'id' attribute of a @KafkaListener or the bean name for spring-managed containers.
      Specified by:
      getListenerId in interface MessageListenerContainer
      Returns:
      the id or bean name.
    • setupMessageListener

      public void setupMessageListener(Object messageListener)
      Description copied from interface: MessageListenerContainer
      Setup the message listener to use. Throws an IllegalArgumentException if that message listener type is not supported.
      Specified by:
      setupMessageListener in interface MessageListenerContainer
      Parameters:
      messageListener - the object to wrapped to the MessageListener.
    • doStart

      protected abstract void doStart()
    • doStop

      protected abstract void doStop()
    • destroy

      public void destroy()
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
      Specified by:
      destroy in interface MessageListenerContainer