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 java.lang.Object implements BeanPostProcessor, Ordered, BeanFactoryAware, BeanClassLoaderAware, EnvironmentAware, SmartInitializingSingleton
Bean post-processor that registers methods annotated withRabbitListenerto be invoked by a AMQP message listener container created under the cover by aRabbitListenerContainerFactoryaccording 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 theEnableRabbitannotation.Auto-detect any
RabbitListenerConfigurerinstances in the container, allowing for customization of the registry to be used, the default container factory or for fine-grained control over endpoints registration. SeeEnableRabbitJavadoc 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 java.lang.StringDEFAULT_RABBIT_LISTENER_CONTAINER_FACTORY_BEAN_NAMEThe bean name of the defaultRabbitListenerContainerFactory.static java.lang.StringRABBIT_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 voidafterSingletonsInstantiated()protected voidassertBeanFactory()intgetOrder()protected java.lang.StringnoBeanFoundMessage(java.lang.Object target, java.lang.String listenerBeanName, java.lang.String requestedBeanName, java.lang.Class<?> expectedClass)java.lang.ObjectpostProcessAfterInitialization(java.lang.Object bean, java.lang.String beanName)java.lang.ObjectpostProcessBeforeInitialization(java.lang.Object bean, java.lang.String beanName)protected java.util.Collection<Declarable>processAmqpListener(RabbitListener rabbitListener, java.lang.reflect.Method method, java.lang.Object bean, java.lang.String beanName)protected java.util.Collection<Declarable>processListener(MethodRabbitListenerEndpoint endpoint, RabbitListener rabbitListener, java.lang.Object bean, java.lang.Object target, java.lang.String beanName)protected java.lang.StringresolveExpressionAsString(java.lang.String value, java.lang.String attribute)voidsetBeanClassLoader(java.lang.ClassLoader classLoader)voidsetBeanFactory(BeanFactory beanFactory)Making aBeanFactoryavailable is optional; if not set,RabbitListenerConfigurerbeans won't get autodetected and anendpoint registryhas to be explicitly configured.voidsetCharset(java.nio.charset.Charset charset)Set a charset for byte[] to String method argument conversion.voidsetContainerFactoryBeanName(java.lang.String containerFactoryBeanName)Set the name of theRabbitListenerContainerFactoryto use by default.voidsetEndpointRegistry(RabbitListenerEndpointRegistry endpointRegistry)Set theRabbitListenerEndpointRegistrythat will hold the created endpoint and manage the lifecycle of the related listener container.voidsetEnvironment(Environment environment)voidsetMessageHandlerMethodFactory(MessageHandlerMethodFactory messageHandlerMethodFactory)Set theMessageHandlerMethodFactoryto 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 java.lang.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 java.lang.String RABBIT_EMPTY_STRING_ARGUMENTS_PROPERTY
- See Also:
- Constant Field Values
-
-
Method Detail
-
setEndpointRegistry
public void setEndpointRegistry(RabbitListenerEndpointRegistry endpointRegistry)
Set theRabbitListenerEndpointRegistrythat will hold the created endpoint and manage the lifecycle of the related listener container.- Parameters:
endpointRegistry- theRabbitListenerEndpointRegistryto set.
-
setContainerFactoryBeanName
public void setContainerFactoryBeanName(java.lang.String containerFactoryBeanName)
Set the name of theRabbitListenerContainerFactoryto use by default.If none is specified, "rabbitListenerContainerFactory" is assumed to be defined.
- Parameters:
containerFactoryBeanName- theRabbitListenerContainerFactorybean name.
-
setMessageHandlerMethodFactory
public void setMessageHandlerMethodFactory(MessageHandlerMethodFactory messageHandlerMethodFactory)
Set theMessageHandlerMethodFactoryto use to configure the message listener responsible to serve an endpoint detected by this processor.By default,
DefaultMessageHandlerMethodFactoryis used and it can be configured further to support additional method arguments or to customize conversion and validation support. SeeDefaultMessageHandlerMethodFactoryJavadoc for more details.- Parameters:
messageHandlerMethodFactory- theMessageHandlerMethodFactoryinstance.
-
setBeanFactory
public void setBeanFactory(BeanFactory beanFactory)
Making aBeanFactoryavailable is optional; if not set,RabbitListenerConfigurerbeans won't get autodetected and anendpoint registryhas to be explicitly configured.- Specified by:
setBeanFactoryin interfaceBeanFactoryAware- Parameters:
beanFactory- theBeanFactoryto be used.
-
setBeanClassLoader
public void setBeanClassLoader(java.lang.ClassLoader classLoader)
- Specified by:
setBeanClassLoaderin interfaceBeanClassLoaderAware
-
setEnvironment
public void setEnvironment(Environment environment)
- Specified by:
setEnvironmentin interfaceEnvironmentAware
-
setCharset
public void setCharset(java.nio.charset.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:
afterSingletonsInstantiatedin interfaceSmartInitializingSingleton
-
postProcessBeforeInitialization
public java.lang.Object postProcessBeforeInitialization(java.lang.Object bean, java.lang.String beanName) throws BeansException- Specified by:
postProcessBeforeInitializationin interfaceBeanPostProcessor- Throws:
BeansException
-
postProcessAfterInitialization
public java.lang.Object postProcessAfterInitialization(java.lang.Object bean, java.lang.String beanName) throws BeansException- Specified by:
postProcessAfterInitializationin interfaceBeanPostProcessor- Throws:
BeansException
-
processAmqpListener
protected java.util.Collection<Declarable> processAmqpListener(RabbitListener rabbitListener, java.lang.reflect.Method method, java.lang.Object bean, java.lang.String beanName)
-
processListener
protected java.util.Collection<Declarable> processListener(MethodRabbitListenerEndpoint endpoint, RabbitListener rabbitListener, java.lang.Object bean, java.lang.Object target, java.lang.String beanName)
-
assertBeanFactory
protected void assertBeanFactory()
-
noBeanFoundMessage
protected java.lang.String noBeanFoundMessage(java.lang.Object target, java.lang.String listenerBeanName, java.lang.String requestedBeanName, java.lang.Class<?> expectedClass)
-
resolveExpressionAsString
protected java.lang.String resolveExpressionAsString(java.lang.String value, java.lang.String attribute)
-
-