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 MessageListenerContainer
s 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
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected MessageListenerContainer
createListenerContainer
(RabbitListenerEndpoint endpoint, RabbitListenerContainerFactory<?> factory) Create and start a newMessageListenerContainer
using the specified factory.void
destroy()
Return theMessageListenerContainer
with the specified id ornull
if no such container exists.Return the ids of the managedMessageListenerContainer
instance(s).int
getPhase()
boolean
boolean
void
void
registerListenerContainer
(RabbitListenerEndpoint endpoint, RabbitListenerContainerFactory<?> factory) Create a message listener container for the givenRabbitListenerEndpoint
.void
registerListenerContainer
(RabbitListenerEndpoint endpoint, RabbitListenerContainerFactory<?> factory, boolean startImmediately) Create a message listener container for the givenRabbitListenerEndpoint
.void
setApplicationContext
(ApplicationContext applicationContext) void
start()
void
stop()
void
Remove a listener container from the registry.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecution
-
Field Details
-
logger
-
-
Constructor Details
-
RabbitListenerEndpointRegistry
public RabbitListenerEndpointRegistry()
-
-
Method Details
-
setApplicationContext
- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- Throws:
BeansException
-
getListenerContainer
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:
-
getListenerContainerIds
Return the ids of the managedMessageListenerContainer
instance(s).- Returns:
- the ids.
- Since:
- 1.5.2
- See Also:
-
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 in regard 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 in regard 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:
-
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
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
-
start
public void start() -
stop
public void stop() -
stop
- Specified by:
stop
in interfaceSmartLifecycle
-
isRunning
public boolean isRunning() -
onApplicationEvent
- Specified by:
onApplicationEvent
in interfaceApplicationListener<ContextRefreshedEvent>
-