Class RabbitListenerAnnotationBeanPostProcessor
- java.lang.Object
-
- org.springframework.amqp.rabbit.annotation.RabbitListenerAnnotationBeanPostProcessor
-
- All Implemented Interfaces:
Aware
,BeanClassLoaderAware
,BeanFactoryAware
,BeanPostProcessor
,SmartInitializingSingleton
,EnvironmentAware
,Ordered
- Direct Known Subclasses:
MultiRabbitListenerAnnotationBeanPostProcessor
,RabbitListenerTestHarness
public class RabbitListenerAnnotationBeanPostProcessor extends Object implements BeanPostProcessor, Ordered, BeanFactoryAware, BeanClassLoaderAware, EnvironmentAware, SmartInitializingSingleton
Bean post-processor that registers methods annotated withRabbitListener
to be invoked by a AMQP message listener container created under the cover by aRabbitListenerContainerFactory
according to the parameters of the annotation.Annotated methods can use flexible arguments as defined by
RabbitListener
.This post-processor is automatically registered by Spring's
<rabbit:annotation-driven>
XML element, and also by theEnableRabbit
annotation.Auto-detect any
RabbitListenerConfigurer
instances in the container, allowing for customization of the registry to be used, the default container factory or for fine-grained control over endpoints registration. SeeEnableRabbit
Javadoc for complete usage details.- Since:
- 1.4
- Author:
- Stephane Nicoll, Juergen Hoeller, Gary Russell, Alex Panchenko, Artem Bilan
- See Also:
RabbitListener
,EnableRabbit
,RabbitListenerConfigurer
,RabbitListenerEndpointRegistrar
,RabbitListenerEndpointRegistry
,RabbitListenerEndpoint
,MethodRabbitListenerEndpoint
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_RABBIT_LISTENER_CONTAINER_FACTORY_BEAN_NAME
The bean name of the defaultRabbitListenerContainerFactory
.static String
RABBIT_EMPTY_STRING_ARGUMENTS_PROPERTY
-
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
-
Constructor Summary
Constructors Constructor Description RabbitListenerAnnotationBeanPostProcessor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterSingletonsInstantiated()
protected void
assertBeanFactory()
int
getOrder()
protected String
noBeanFoundMessage(Object target, String listenerBeanName, String requestedBeanName, Class<?> expectedClass)
Object
postProcessAfterInitialization(Object bean, String beanName)
Object
postProcessBeforeInitialization(Object bean, String beanName)
protected Collection<Declarable>
processAmqpListener(RabbitListener rabbitListener, Method method, Object bean, String beanName)
protected Collection<Declarable>
processListener(MethodRabbitListenerEndpoint endpoint, RabbitListener rabbitListener, Object bean, Object target, String beanName)
protected String
resolveExpressionAsString(String value, String attribute)
void
setBeanClassLoader(ClassLoader classLoader)
void
setBeanFactory(BeanFactory beanFactory)
Making aBeanFactory
available is optional; if not set,RabbitListenerConfigurer
beans won't get autodetected and anendpoint registry
has to be explicitly configured.void
setCharset(Charset charset)
Set a charset for byte[] to String method argument conversion.void
setContainerFactoryBeanName(String containerFactoryBeanName)
Set the name of theRabbitListenerContainerFactory
to use by default.void
setEndpointRegistry(RabbitListenerEndpointRegistry endpointRegistry)
Set theRabbitListenerEndpointRegistry
that will hold the created endpoint and manage the lifecycle of the related listener container.void
setEnvironment(Environment environment)
void
setMessageHandlerMethodFactory(MessageHandlerMethodFactory messageHandlerMethodFactory)
Set theMessageHandlerMethodFactory
to use to configure the message listener responsible to serve an endpoint detected by this processor.
-
-
-
Field Detail
-
DEFAULT_RABBIT_LISTENER_CONTAINER_FACTORY_BEAN_NAME
public static final String DEFAULT_RABBIT_LISTENER_CONTAINER_FACTORY_BEAN_NAME
The bean name of the defaultRabbitListenerContainerFactory
.- See Also:
- Constant Field Values
-
RABBIT_EMPTY_STRING_ARGUMENTS_PROPERTY
public static final String RABBIT_EMPTY_STRING_ARGUMENTS_PROPERTY
- See Also:
- Constant Field Values
-
-
Method Detail
-
setEndpointRegistry
public void setEndpointRegistry(RabbitListenerEndpointRegistry endpointRegistry)
Set theRabbitListenerEndpointRegistry
that will hold the created endpoint and manage the lifecycle of the related listener container.- Parameters:
endpointRegistry
- theRabbitListenerEndpointRegistry
to set.
-
setContainerFactoryBeanName
public void setContainerFactoryBeanName(String containerFactoryBeanName)
Set the name of theRabbitListenerContainerFactory
to use by default.If none is specified, "rabbitListenerContainerFactory" is assumed to be defined.
- Parameters:
containerFactoryBeanName
- theRabbitListenerContainerFactory
bean name.
-
setMessageHandlerMethodFactory
public void setMessageHandlerMethodFactory(MessageHandlerMethodFactory messageHandlerMethodFactory)
Set theMessageHandlerMethodFactory
to use to configure the message listener responsible to serve an endpoint detected by this processor.By default,
DefaultMessageHandlerMethodFactory
is used and it can be configured further to support additional method arguments or to customize conversion and validation support. SeeDefaultMessageHandlerMethodFactory
Javadoc for more details.- Parameters:
messageHandlerMethodFactory
- theMessageHandlerMethodFactory
instance.
-
setBeanFactory
public void setBeanFactory(BeanFactory beanFactory)
Making aBeanFactory
available is optional; if not set,RabbitListenerConfigurer
beans won't get autodetected and anendpoint registry
has to be explicitly configured.- Specified by:
setBeanFactory
in interfaceBeanFactoryAware
- Parameters:
beanFactory
- theBeanFactory
to be used.
-
setBeanClassLoader
public void setBeanClassLoader(ClassLoader classLoader)
- Specified by:
setBeanClassLoader
in interfaceBeanClassLoaderAware
-
setEnvironment
public void setEnvironment(Environment environment)
- Specified by:
setEnvironment
in interfaceEnvironmentAware
-
setCharset
public void setCharset(Charset charset)
Set a charset for byte[] to String method argument conversion.- Parameters:
charset
- the charset (default UTF-8).- Since:
- 2.2
-
afterSingletonsInstantiated
public void afterSingletonsInstantiated()
- Specified by:
afterSingletonsInstantiated
in interfaceSmartInitializingSingleton
-
postProcessBeforeInitialization
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
- Specified by:
postProcessBeforeInitialization
in interfaceBeanPostProcessor
- Throws:
BeansException
-
postProcessAfterInitialization
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
- Specified by:
postProcessAfterInitialization
in interfaceBeanPostProcessor
- Throws:
BeansException
-
processAmqpListener
protected Collection<Declarable> processAmqpListener(RabbitListener rabbitListener, Method method, Object bean, String beanName)
-
processListener
protected Collection<Declarable> processListener(MethodRabbitListenerEndpoint endpoint, RabbitListener rabbitListener, Object bean, Object target, String beanName)
-
assertBeanFactory
protected void assertBeanFactory()
-
noBeanFoundMessage
protected String noBeanFoundMessage(Object target, String listenerBeanName, String requestedBeanName, Class<?> expectedClass)
-
-