Class KafkaListenerEndpointRegistry
- All Implemented Interfaces:
EventListener,Aware,DisposableBean,ApplicationContextAware,ApplicationListener<ContextRefreshedEvent>,Lifecycle,Phased,SmartLifecycle,ListenerContainerRegistry
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.
- Author:
- Stephane Nicoll, Juergen Hoeller, Artem Bilan, Gary Russell, Asi Bross
- See Also:
-
Field Summary
FieldsFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected MessageListenerContainercreateListenerContainer(KafkaListenerEndpoint endpoint, KafkaListenerContainerFactory<?> factory) Create and start a newMessageListenerContainerusing the specified factory.voiddestroy()Return allMessageListenerContainerinstances including those managed by this registry and those declared as beans in the application context.Return theMessageListenerContainerwith the specified id ornullif no such container exists.Return the ids of the managedMessageListenerContainerinstance(s).Return the managedMessageListenerContainerinstance(s).intgetPhase()Return theMessageListenerContainerwith the specified id ornullif no such container exists.booleanbooleanvoidvoidregisterListenerContainer(KafkaListenerEndpoint endpoint, KafkaListenerContainerFactory<?> factory) Create a message listener container for the givenKafkaListenerEndpoint.voidregisterListenerContainer(KafkaListenerEndpoint endpoint, KafkaListenerContainerFactory<?> factory, boolean startImmediately) Create a message listener container for the givenKafkaListenerEndpoint.voidsetAlwaysStartAfterRefresh(boolean alwaysStartAfterRefresh) By default, containers registered for endpoints after the context is refreshed are immediately started, regardless of their autoStartup property, to comply with theSmartLifecyclecontract, where autoStartup is only considered during context initialization.voidsetApplicationContext(ApplicationContext applicationContext) voidstart()voidstop()voidUnregister the listener container with the provided id.
-
Field Details
-
logger
-
-
Constructor Details
-
KafkaListenerEndpointRegistry
public KafkaListenerEndpointRegistry()
-
-
Method Details
-
setApplicationContext
- Specified by:
setApplicationContextin interfaceApplicationContextAware- Throws:
BeansException
-
getListenerContainer
Return theMessageListenerContainerwith the specified id ornullif no such container exists.- Specified by:
getListenerContainerin interfaceListenerContainerRegistry- Parameters:
id- the id of the container- Returns:
- the container or
nullif no container with that id exists - See Also:
-
getUnregisteredListenerContainer
Description copied from interface:ListenerContainerRegistryReturn theMessageListenerContainerwith the specified id ornullif no such container exists. Returns containers that are not registered with the registry, but exist in the application context.- Specified by:
getUnregisteredListenerContainerin interfaceListenerContainerRegistry- Parameters:
id- the id of the container- Returns:
- the container or
nullif no container with that id exists - See Also:
-
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 theSmartLifecyclecontract, 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
-
getListenerContainerIds
Return the ids of the managedMessageListenerContainerinstance(s).- Specified by:
getListenerContainerIdsin interfaceListenerContainerRegistry- Returns:
- the ids.
- See Also:
-
getListenerContainers
Return the managedMessageListenerContainerinstance(s).- Specified by:
getListenerContainersin interfaceListenerContainerRegistry- Returns:
- the managed
MessageListenerContainerinstance(s). - See Also:
-
getAllListenerContainers
Return allMessageListenerContainerinstances including those managed by this registry and those declared as beans in the application context. Prototype-scoped containers will be included. Lazy beans that have not yet been created will not be initialized by a call to this method.- Specified by:
getAllListenerContainersin interfaceListenerContainerRegistry- Returns:
- the
MessageListenerContainerinstance(s). - Since:
- 2.2.5
- See Also:
-
registerListenerContainer
public void registerListenerContainer(KafkaListenerEndpoint endpoint, KafkaListenerContainerFactory<?> factory) Create a message listener container for the givenKafkaListenerEndpoint.This create the necessary infrastructure to honor that endpoint with regards to its configuration.
- Parameters:
endpoint- the endpoint to addfactory- the listener factory to use- See Also:
-
registerListenerContainer
public void registerListenerContainer(KafkaListenerEndpoint endpoint, KafkaListenerContainerFactory<?> factory, boolean startImmediately) Create a message listener container for the givenKafkaListenerEndpoint.This create the necessary infrastructure to honor that endpoint with regards to its configuration.
The
startImmediatelyflag determines if the container should be started immediately.- Parameters:
endpoint- the endpoint to add.factory- theKafkaListenerContainerFactoryto use.startImmediately- start the container immediately if necessary- See Also:
-
unregisterListenerContainer
Unregister the listener container with the provided id.IMPORTANT: this method simply removes the container from the registry. It does NOT call any
LifecycleorDisposableBeanmethods; 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
-
createListenerContainer
protected MessageListenerContainer createListenerContainer(KafkaListenerEndpoint endpoint, KafkaListenerContainerFactory<?> factory) Create and start a newMessageListenerContainerusing the specified factory.- Parameters:
endpoint- the endpoint to create aMessageListenerContainer.factory- theKafkaListenerContainerFactoryto use.- Returns:
- the
MessageListenerContainer.
-
destroy
public void destroy()- Specified by:
destroyin interfaceDisposableBean
-
getPhase
public int getPhase()- Specified by:
getPhasein interfacePhased- Specified by:
getPhasein interfaceSmartLifecycle
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartupin interfaceSmartLifecycle
-
start
public void start() -
stop
public void stop() -
stop
- Specified by:
stopin interfaceSmartLifecycle
-
isRunning
public boolean isRunning() -
onApplicationEvent
- Specified by:
onApplicationEventin interfaceApplicationListener<ContextRefreshedEvent>
-