Class RabbitListenerEndpointRegistry
java.lang.Object
org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry
- All Implemented Interfaces:
EventListener,Aware,DisposableBean,ApplicationContextAware,ApplicationListener<ContextRefreshedEvent>,Lifecycle,Phased,SmartLifecycle
public class RabbitListenerEndpointRegistry
extends Object
implements DisposableBean, SmartLifecycle, ApplicationContextAware, ApplicationListener<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.
- Since:
- 1.4
- Author:
- Stephane Nicoll, Juergen Hoeller, Artem Bilan, Gary Russell
- See Also:
-
Field Summary
FieldsFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected MessageListenerContainercreateListenerContainer(RabbitListenerEndpoint endpoint, RabbitListenerContainerFactory<?> factory) Create and start a newMessageListenerContainerusing the specified factory.voiddestroy()Return theMessageListenerContainerwith the specified id ornullif no such container exists.Return the ids of the managedMessageListenerContainerinstance(s).intgetPhase()booleanbooleanvoidvoidregisterListenerContainer(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()voidRemove a listener container from the registry.
-
Field Details
-
logger
-
-
Constructor Details
-
RabbitListenerEndpointRegistry
public RabbitListenerEndpointRegistry()
-
-
Method Details
-
setApplicationContext
- Specified by:
setApplicationContextin interfaceApplicationContextAware- Throws:
BeansException
-
getListenerContainer
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:
-
getListenerContainerIds
Return the ids of the managedMessageListenerContainerinstance(s).- Returns:
- the ids.
- Since:
- 1.5.2
- See Also:
-
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
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:
-
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
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
-
start
public void start() -
stop
public void stop() -
stop
- Specified by:
stopin interfaceSmartLifecycle
-
isRunning
public boolean isRunning() -
onApplicationEvent
- Specified by:
onApplicationEventin interfaceApplicationListener<ContextRefreshedEvent>
-