Package org.springframework.kafka.config
Class KafkaListenerEndpointRegistry
- java.lang.Object
-
- org.springframework.kafka.config.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 necessaryMessageListenerContainerinstances 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. UsegetListenerContainers()if you need to access this registry's listener containers for management purposes. If you need to access to a specific message listener container, usegetListenerContainer(String)with the id of the endpoint.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.springframework.core.log.LogAccessorlogger
-
Constructor Summary
Constructors Constructor Description KafkaListenerEndpointRegistry()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected MessageListenerContainercreateListenerContainer(KafkaListenerEndpoint endpoint, KafkaListenerContainerFactory<?> factory)Create and start a newMessageListenerContainerusing the specified factory.voiddestroy()java.util.Collection<MessageListenerContainer>getAllListenerContainers()Return allMessageListenerContainerinstances including those managed by this registry and those declared as beans in the application context.MessageListenerContainergetListenerContainer(java.lang.String id)Return theMessageListenerContainerwith the specified id ornullif no such container exists.java.util.Set<java.lang.String>getListenerContainerIds()Return the ids of the managedMessageListenerContainerinstance(s).java.util.Collection<MessageListenerContainer>getListenerContainers()Return the managedMessageListenerContainerinstance(s).intgetPhase()booleanisAutoStartup()booleanisRunning()voidonApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)voidregisterListenerContainer(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.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext)voidstart()voidstop()voidstop(java.lang.Runnable callback)
-
-
-
Method Detail
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException- Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
getListenerContainer
@Nullable public MessageListenerContainer getListenerContainer(java.lang.String id)
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:
KafkaListenerEndpoint.getId(),getListenerContainerIds()
-
getListenerContainerIds
public java.util.Set<java.lang.String> getListenerContainerIds()
Return the ids of the managedMessageListenerContainerinstance(s).- Specified by:
getListenerContainerIdsin interfaceListenerContainerRegistry- Returns:
- the ids.
- See Also:
getListenerContainer(String)
-
getListenerContainers
public java.util.Collection<MessageListenerContainer> getListenerContainers()
Return the managedMessageListenerContainerinstance(s).- Specified by:
getListenerContainersin interfaceListenerContainerRegistry- Returns:
- the managed
MessageListenerContainerinstance(s). - See Also:
getAllListenerContainers()
-
getAllListenerContainers
public java.util.Collection<MessageListenerContainer> 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:
getListenerContainers()
-
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(KafkaListenerEndpoint, KafkaListenerContainerFactory, boolean)
-
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:
getListenerContainers(),getListenerContainer(String)
-
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 interfaceorg.springframework.beans.factory.DisposableBean
-
getPhase
public int getPhase()
- Specified by:
getPhasein interfaceorg.springframework.context.Phased- Specified by:
getPhasein interfaceorg.springframework.context.SmartLifecycle
-
isAutoStartup
public boolean isAutoStartup()
- Specified by:
isAutoStartupin interfaceorg.springframework.context.SmartLifecycle
-
start
public void start()
- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()
- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop(java.lang.Runnable callback)
- Specified by:
stopin interfaceorg.springframework.context.SmartLifecycle
-
isRunning
public boolean isRunning()
- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
onApplicationEvent
public void onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)
- Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
-
-