Interface MessageListenerContainer

  • All Superinterfaces:
    org.springframework.beans.factory.DisposableBean, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle
    All Known Subinterfaces:
    GenericMessageListenerContainer<K,​V>
    All Known Implementing Classes:
    AbstractMessageListenerContainer, ConcurrentMessageListenerContainer, KafkaMessageListenerContainer

    public interface MessageListenerContainer
    extends org.springframework.context.SmartLifecycle, org.springframework.beans.factory.DisposableBean
    Internal abstraction used by the framework representing a message listener container. Not meant to be implemented externally.
    • Field Summary

      • Fields inherited from interface org.springframework.context.SmartLifecycle

        DEFAULT_PHASE
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default void destroy()  
      default java.util.Collection<org.apache.kafka.common.TopicPartition> getAssignedPartitions()
      Return the assigned topics/partitions for this container.
      default 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.
      default MessageListenerContainer getContainerFor​(java.lang.String topic, int partition)
      If this container has child containers, return the child container that is assigned the topic/partition.
      default ContainerProperties getContainerProperties()
      Return the container properties for this container.
      default java.lang.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.
      default java.lang.String getListenerId()
      The 'id' attribute of a @KafkaListener or the bean name for spring-managed containers.
      default byte[] getListenerInfo()
      Get arbitrary static information that will be added to the KafkaHeaders.LISTENER_INFO header of all records.
      default boolean isChildRunning()
      If this container has child containers, return true if at least one child is running.
      default boolean isContainerPaused()
      Return true if pause() has been called; and all consumers in this container have actually paused.
      default boolean isInExpectedState()
      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 isPauseRequested()
      Return true if pause() has been called; the container might not have actually paused yet.
      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 by client-id.
      default void pause()
      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()
      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​(java.lang.Object messageListener)
      Setup the message listener to use.
      default void stopAbnormally​(java.lang.Runnable callback)
      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 Detail

      • setupMessageListener

        void setupMessageListener​(java.lang.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

        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 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 java.util.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 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.
        Returns:
        the topics/partitions.
        Since:
        2.5
      • 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:
        SmartLifecycle
      • getGroupId

        @Nullable
        default java.lang.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

        @Nullable
        default java.lang.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
      • 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(Runnable)
      • stopAbnormally

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

        default MessageListenerContainer getContainerFor​(java.lang.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.
      • destroy

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