Class KafkaListenerEndpointRegistry

  • All Implemented Interfaces:
    java.util.EventListener, org.springframework.beans.factory.Aware, org.springframework.beans.factory.DisposableBean, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle, ListenerContainerRegistry

    public class KafkaListenerEndpointRegistry
    extends java.lang.Object
    implements ListenerContainerRegistry, org.springframework.beans.factory.DisposableBean, org.springframework.context.SmartLifecycle, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
    Creates the necessary MessageListenerContainer instances for the registered endpoints. Also manages the lifecycle of the listener containers, in particular within the lifecycle of the application context.

    Contrary to MessageListenerContainers created manually, listener containers managed by registry are not beans in the application context and are not candidates for autowiring. Use getListenerContainers() if you need to access this registry's listener containers for management purposes. If you need to access to a specific message listener container, use getListenerContainer(String) with the id of the endpoint.

    See Also:
    KafkaListenerEndpoint, MessageListenerContainer, KafkaListenerContainerFactory
    • Field Detail

      • logger

        protected final org.springframework.core.log.LogAccessor logger
    • Constructor Detail

      • KafkaListenerEndpointRegistry

        public KafkaListenerEndpointRegistry()
    • Method Detail

      • 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
      • setAlwaysStartAfterRefresh

        public void setAlwaysStartAfterRefresh​(boolean alwaysStartAfterRefresh)
        By default, containers registered for endpoints after the context is refreshed are immediately started, regardless of their autoStartup property, to comply with the SmartLifecycle contract, where autoStartup is only considered during context initialization. Set to false to apply the autoStartup property, even for late endpoint binding. If this is called after the context is refreshed, it will apply to any endpoints registered after that call.
        Parameters:
        alwaysStartAfterRefresh - false to apply the property.
        Since:
        2.8.7
      • unregisterListenerContainer

        @Nullable
        public MessageListenerContainer unregisterListenerContainer​(java.lang.String id)
        Unregister the listener container with the provided id.

        IMPORTANT: this method simply removes the container from the registry. It does NOT call any Lifecycle or DisposableBean methods; you need to call them before or after calling this method to shut down the container.

        Parameters:
        id - the id.
        Returns:
        the container, if it was registered; null otherwise.
        Since:
        2.8.9
      • destroy

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

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

        public boolean isAutoStartup()
        Specified by:
        isAutoStartup 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
      • stop

        public void stop​(java.lang.Runnable callback)
        Specified by:
        stop in interface org.springframework.context.SmartLifecycle
      • isRunning

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

        public void onApplicationEvent​(org.springframework.context.event.ContextRefreshedEvent event)
        Specified by:
        onApplicationEvent in interface org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>