Class RabbitListenerEndpointRegistry
- java.lang.Object
-
- org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry
-
- All Implemented Interfaces:
java.util.EventListener,Aware,DisposableBean,ApplicationContextAware,ApplicationListener<ContextRefreshedEvent>,Lifecycle,Phased,SmartLifecycle
public class RabbitListenerEndpointRegistry extends java.lang.Object implements DisposableBean, SmartLifecycle, ApplicationContextAware, ApplicationListener<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.- Since:
- 1.4
- Author:
- Stephane Nicoll, Juergen Hoeller, Artem Bilan, Gary Russell
- See Also:
RabbitListenerEndpoint,MessageListenerContainer,RabbitListenerContainerFactory
-
-
Field Summary
Fields Modifier and Type Field Description protected Loglogger-
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
-
Constructor Summary
Constructors Constructor Description RabbitListenerEndpointRegistry()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected MessageListenerContainercreateListenerContainer(RabbitListenerEndpoint endpoint, RabbitListenerContainerFactory<?> factory)Create and start a newMessageListenerContainerusing the specified factory.voiddestroy()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()intgetPhase()booleanisAutoStartup()booleanisRunning()voidonApplicationEvent(ContextRefreshedEvent event)voidregisterListenerContainer(RabbitListenerEndpoint endpoint, RabbitListenerContainerFactory<?> factory)Create a message listener container for the givenRabbitListenerEndpoint.voidregisterListenerContainer(RabbitListenerEndpoint endpoint, RabbitListenerContainerFactory<?> factory, boolean startImmediately)Create a message listener container for the givenRabbitListenerEndpoint.voidsetApplicationContext(ApplicationContext applicationContext)voidstart()voidstop()voidstop(java.lang.Runnable callback)MessageListenerContainerunregisterListenerContainer(java.lang.String id)Remove a listener container from the registry.
-
-
-
Field Detail
-
logger
protected final Log logger
-
-
Method Detail
-
setApplicationContext
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
- Specified by:
setApplicationContextin interfaceApplicationContextAware- Throws:
BeansException
-
getListenerContainer
public MessageListenerContainer getListenerContainer(java.lang.String id)
Return theMessageListenerContainerwith the specified id ornullif no such container exists.- Parameters:
id- the id of the container- Returns:
- the container or
nullif no container with that id exists - See Also:
RabbitListenerEndpoint.getId(),getListenerContainerIds()
-
getListenerContainerIds
public java.util.Set<java.lang.String> getListenerContainerIds()
Return the ids of the managedMessageListenerContainerinstance(s).- Returns:
- the ids.
- Since:
- 1.5.2
- See Also:
getListenerContainer(String)
-
getListenerContainers
public java.util.Collection<MessageListenerContainer> getListenerContainers()
- Returns:
- the managed
MessageListenerContainerinstance(s).
-
registerListenerContainer
public void registerListenerContainer(RabbitListenerEndpoint endpoint, RabbitListenerContainerFactory<?> factory)
Create a message listener container for the givenRabbitListenerEndpoint.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(RabbitListenerEndpoint, RabbitListenerContainerFactory, boolean)
-
registerListenerContainer
public void registerListenerContainer(RabbitListenerEndpoint endpoint, RabbitListenerContainerFactory<?> factory, boolean startImmediately)
Create a message listener container for the givenRabbitListenerEndpoint.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- theRabbitListenerContainerFactoryto use.startImmediately- start the container immediately if necessary- See Also:
getListenerContainers(),getListenerContainer(String)
-
createListenerContainer
protected MessageListenerContainer createListenerContainer(RabbitListenerEndpoint endpoint, RabbitListenerContainerFactory<?> factory)
Create and start a newMessageListenerContainerusing the specified factory.- Parameters:
endpoint- the endpoint to create aMessageListenerContainer.factory- theRabbitListenerContainerFactoryto use.- Returns:
- the
MessageListenerContainer.
-
unregisterListenerContainer
@Nullable public MessageListenerContainer unregisterListenerContainer(java.lang.String id)
Remove a listener container from the registry.- Parameters:
id- the container id.- Returns:
- the container, or null if there is no registration matching the id.
- Since:
- 2.0.6
-
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
-
stop
public void stop(java.lang.Runnable callback)
- Specified by:
stopin interfaceSmartLifecycle
-
onApplicationEvent
public void onApplicationEvent(ContextRefreshedEvent event)
- Specified by:
onApplicationEventin interfaceApplicationListener<ContextRefreshedEvent>
-
-