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 necessaryMessageListenerContainer
instances for the registered endpoints. Also manages the lifecycle of the listener containers, in particular within the lifecycle of the application context.Contrary to
MessageListenerContainer
s 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 Log
logger
-
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
-
Constructor Summary
Constructors Constructor Description RabbitListenerEndpointRegistry()
-
Method Summary
-
-
-
Field Detail
-
logger
protected final Log logger
-
-
Method Detail
-
setApplicationContext
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- Throws:
BeansException
-
getListenerContainer
public MessageListenerContainer getListenerContainer(String id)
Return theMessageListenerContainer
with the specified id ornull
if no such container exists.- Parameters:
id
- the id of the container- Returns:
- the container or
null
if no container with that id exists - See Also:
RabbitListenerEndpoint.getId()
,getListenerContainerIds()
-
getListenerContainerIds
public Set<String> getListenerContainerIds()
Return the ids of the managedMessageListenerContainer
instance(s).- Returns:
- the ids.
- Since:
- 1.5.2
- See Also:
getListenerContainer(String)
-
getListenerContainers
public Collection<MessageListenerContainer> getListenerContainers()
- Returns:
- the managed
MessageListenerContainer
instance(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
startImmediately
flag determines if the container should be started immediately.- Parameters:
endpoint
- the endpoint to add.factory
- theRabbitListenerContainerFactory
to 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 newMessageListenerContainer
using the specified factory.- Parameters:
endpoint
- the endpoint to create aMessageListenerContainer
.factory
- theRabbitListenerContainerFactory
to use.- Returns:
- the
MessageListenerContainer
.
-
unregisterListenerContainer
@Nullable public MessageListenerContainer unregisterListenerContainer(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:
destroy
in interfaceDisposableBean
-
getPhase
public int getPhase()
- Specified by:
getPhase
in interfacePhased
- Specified by:
getPhase
in interfaceSmartLifecycle
-
isAutoStartup
public boolean isAutoStartup()
- Specified by:
isAutoStartup
in interfaceSmartLifecycle
-
stop
public void stop(Runnable callback)
- Specified by:
stop
in interfaceSmartLifecycle
-
onApplicationEvent
public void onApplicationEvent(ContextRefreshedEvent event)
- Specified by:
onApplicationEvent
in interfaceApplicationListener<ContextRefreshedEvent>
-
-