Interface MessageListenerContainer

All Superinterfaces:
DisposableBean, Lifecycle, Phased, SmartLifecycle
All Known Subinterfaces:
GenericMessageListenerContainer<K,V>
All Known Implementing Classes:
AbstractMessageListenerContainer, ConcurrentMessageListenerContainer, KafkaMessageListenerContainer

public interface MessageListenerContainer extends SmartLifecycle, DisposableBean
Internal abstraction used by the framework representing a message listener container. Not meant to be implemented externally.
Author:
Stephane Nicoll, Gary Russell, Vladimir Tsanev, Tomaz Fernandes, Francois Rosiere, Soby Chacko
  • Field Summary

    Fields inherited from interface org.springframework.context.SmartLifecycle

    DEFAULT_PHASE
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Notify a parent container that a child container has stopped.
    default void
     
    default void
    Alerting the consumer to trigger an enforced rebalance.
    default Collection<org.apache.kafka.common.TopicPartition>
    Return the assigned topics/partitions for this container.
    default Map<String,Collection<org.apache.kafka.common.TopicPartition>>
    Return the assigned topics/partitions for this container, by client.id.
    getContainerFor(String topic, int partition)
    If this container has child containers, return the child container that is assigned the topic/partition.
    Return the container properties for this container.
    default String
    Return the group.id property for this container whether specifically set on the container or via a consumer property on the consumer factory.
    default String
    The 'id' attribute of a @KafkaListener or the bean name for spring-managed containers.
    default byte[]
    Get arbitrary static information that will be added to the KafkaHeaders.LISTENER_INFO header of all records.
    default String
    The 'id' attribute of the main @KafkaListener container, if this container is for a retry topic; null otherwise.
    default boolean
    If this container has child containers, return true if at least one child is running.
    default boolean
    Return true if pause() has been called; and all consumers in this container have actually paused.
    default boolean
    Return true if the container is running, has never been started, or has been stopped.
    default boolean
    isPartitionPaused(org.apache.kafka.common.TopicPartition topicPartition)
    Whether or not this topic's partition is currently paused.
    default boolean
    isPartitionPauseRequested(org.apache.kafka.common.TopicPartition topicPartition)
    Whether or not this topic's partition pause has been requested.
    default boolean
    Return true if pause() has been called; the container might not have actually paused yet.
    Map<String,Map<org.apache.kafka.common.MetricName,? extends org.apache.kafka.common.Metric>>
    Return metrics kept by this container's consumer(s), grouped by client-id.
    default void
    Pause this container before the next poll().
    default void
    pausePartition(org.apache.kafka.common.TopicPartition topicPartition)
    Pause this partition before the next poll().
    default void
    Resume this container, if paused, after the next poll().
    default void
    resumePartition(org.apache.kafka.common.TopicPartition topicPartition)
    Resume this partition, if paused, after the next poll().
    default void
    setAutoStartup(boolean autoStartup)
    Set the autoStartup.
    void
    setupMessageListener(Object messageListener)
    Setup the message listener to use.
    default void
    Stop the container after some exception so that isInExpectedState() will return false.

    Methods inherited from interface org.springframework.context.Lifecycle

    isRunning, start, stop

    Methods inherited from interface org.springframework.context.SmartLifecycle

    getPhase, isAutoStartup, stop
  • Method Details

    • setupMessageListener

      void setupMessageListener(Object messageListener)
      Setup the message listener to use. Throws an IllegalArgumentException if that message listener type is not supported.
      Parameters:
      messageListener - the object to wrapped to the MessageListener.
    • metrics

      Map<String,Map<org.apache.kafka.common.MetricName,? extends org.apache.kafka.common.Metric>> metrics()
      Return metrics kept by this container's consumer(s), grouped by client-id.
      Returns:
      the consumer(s) metrics grouped by client-id
      Since:
      1.3
      See Also:
      • Consumer.metrics()
    • getContainerProperties

      default ContainerProperties getContainerProperties()
      Return the container properties for this container.
      Returns:
      the properties.
      Since:
      2.1.3
    • getAssignedPartitions

      @Nullable default Collection<org.apache.kafka.common.TopicPartition> getAssignedPartitions()
      Return the assigned topics/partitions for this container.
      Returns:
      the topics/partitions.
      Since:
      2.1.3
    • getAssignmentsByClientId

      @Nullable default Map<String,Collection<org.apache.kafka.common.TopicPartition>> getAssignmentsByClientId()
      Return the assigned topics/partitions for this container, by client.id.
      Returns:
      the topics/partitions.
      Since:
      2.5
    • enforceRebalance

      default void enforceRebalance()
      Alerting the consumer to trigger an enforced rebalance. The actual enforce will happen when the next poll() operation is invoked.
      Since:
      3.1.2
      See Also:
      • KafkaConsumer.enforceRebalance()
    • pause

      default void pause()
      Pause this container before the next poll(). This is a thread-safe operation, the actual pause is processed by the consumer thread.
      Since:
      2.1.3
      See Also:
      • KafkaConsumer.pause(Collection)
    • resume

      default void resume()
      Resume this container, if paused, after the next poll(). This is a thread-safe operation, the actual resume is processed by the consumer thread.
      Since:
      2.1.3
      See Also:
      • KafkaConsumer.resume(Collection)
    • pausePartition

      default void pausePartition(org.apache.kafka.common.TopicPartition topicPartition)
      Pause this partition before the next poll(). This is a thread-safe operation, the actual pause is processed by the consumer thread.
      Parameters:
      topicPartition - the topicPartition to pause.
      Since:
      2.7
    • resumePartition

      default void resumePartition(org.apache.kafka.common.TopicPartition topicPartition)
      Resume this partition, if paused, after the next poll(). This is a thread-safe operation, the actual pause is processed by the consumer thread.
      Parameters:
      topicPartition - the topicPartition to resume.
      Since:
      2.7
    • isPartitionPauseRequested

      default boolean isPartitionPauseRequested(org.apache.kafka.common.TopicPartition topicPartition)
      Whether or not this topic's partition pause has been requested.
      Parameters:
      topicPartition - the topic partition to check
      Returns:
      true if pause for this TopicPartition has been requested
      Since:
      2.7
    • isPartitionPaused

      default boolean isPartitionPaused(org.apache.kafka.common.TopicPartition topicPartition)
      Whether or not this topic's partition is currently paused.
      Parameters:
      topicPartition - the topic partition to check
      Returns:
      true if this partition has been paused.
      Since:
      2.7
    • isPauseRequested

      default boolean isPauseRequested()
      Return true if pause() has been called; the container might not have actually paused yet.
      Returns:
      true if pause has been requested.
      Since:
      2.1.5
    • isContainerPaused

      default boolean isContainerPaused()
      Return true if pause() has been called; and all consumers in this container have actually paused.
      Returns:
      true if the container is paused.
      Since:
      2.1.5
    • setAutoStartup

      default void setAutoStartup(boolean autoStartup)
      Set the autoStartup.
      Parameters:
      autoStartup - the autoStartup to set.
      Since:
      2.2
      See Also:
    • getGroupId

      @Nullable default String getGroupId()
      Return the group.id property for this container whether specifically set on the container or via a consumer property on the consumer factory.
      Returns:
      the group id.
      Since:
      2.2.5
    • getListenerId

      default String getListenerId()
      The 'id' attribute of a @KafkaListener or the bean name for spring-managed containers.
      Returns:
      the id or bean name.
      Since:
      2.2.5
    • getMainListenerId

      @Nullable default String getMainListenerId()
      The 'id' attribute of the main @KafkaListener container, if this container is for a retry topic; null otherwise.
      Returns:
      the id.
      Since:
      3.0
    • getListenerInfo

      @Nullable default byte[] getListenerInfo()
      Get arbitrary static information that will be added to the KafkaHeaders.LISTENER_INFO header of all records.
      Returns:
      the info.
      Since:
      2.8.6
    • isChildRunning

      default boolean isChildRunning()
      If this container has child containers, return true if at least one child is running. If there are not child containers, returns Lifecycle.isRunning().
      Returns:
      true if a child is running.
      Since:
      2.7.3
    • isInExpectedState

      default boolean isInExpectedState()
      Return true if the container is running, has never been started, or has been stopped.
      Returns:
      true if the state is as expected.
      Since:
      2.8
      See Also:
    • stopAbnormally

      default void stopAbnormally(Runnable callback)
      Stop the container after some exception so that isInExpectedState() will return false.
      Parameters:
      callback - the callback.
      Since:
      2.8
      See Also:
    • getContainerFor

      default MessageListenerContainer getContainerFor(String topic, int partition)
      If this container has child containers, return the child container that is assigned the topic/partition. Return this when there are no child containers.
      Parameters:
      topic - the topic.
      partition - the partition.
      Returns:
      the container.
    • childStopped

      default void childStopped(MessageListenerContainer child, ConsumerStoppedEvent.Reason reason)
      Notify a parent container that a child container has stopped.
      Parameters:
      child - the container.
      reason - the reason.
      Since:
      2.9.7
    • destroy

      default void destroy()
      Specified by:
      destroy in interface DisposableBean