Class KafkaListenerAnnotationBeanPostProcessor<K,V>
- java.lang.Object
-
- org.springframework.kafka.annotation.KafkaListenerAnnotationBeanPostProcessor<K,V>
-
- Type Parameters:
K
- the key type.V
- the value type.
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.config.BeanPostProcessor
,org.springframework.beans.factory.InitializingBean
,org.springframework.beans.factory.SmartInitializingSingleton
,org.springframework.context.ApplicationContextAware
,org.springframework.core.Ordered
public class KafkaListenerAnnotationBeanPostProcessor<K,V> extends java.lang.Object implements org.springframework.beans.factory.config.BeanPostProcessor, org.springframework.core.Ordered, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.SmartInitializingSingleton
Bean post-processor that registers methods annotated withKafkaListener
to be invoked by a Kafka message listener container created under the covers by aKafkaListenerContainerFactory
according to the parameters of the annotation.Annotated methods can use flexible arguments as defined by
KafkaListener
.This post-processor is automatically registered by Spring's
EnableKafka
annotation.Auto-detect any
KafkaListenerConfigurer
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. SeeEnableKafka
Javadoc for complete usage details.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
KafkaListenerAnnotationBeanPostProcessor.AnnotationEnhancer
Post processes each set of annotation attributes.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_KAFKA_LISTENER_CONTAINER_FACTORY_BEAN_NAME
The bean name of the defaultKafkaListenerContainerFactory
.
-
Constructor Summary
Constructors Constructor Description KafkaListenerAnnotationBeanPostProcessor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
void
afterSingletonsInstantiated()
protected void
assertBeanFactory()
KafkaListenerEndpointRegistrar
getEndpointRegistrar()
Return theKafkaListenerEndpointRegistrar
.org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory
getMessageHandlerMethodFactory()
Return the configured handler factory.int
getOrder()
protected java.lang.String
noBeanFoundMessage(java.lang.Object target, java.lang.String listenerBeanName, java.lang.String requestedBeanName, java.lang.Class<?> expectedClass)
java.lang.Object
postProcessAfterInitialization(java.lang.Object bean, java.lang.String beanName)
java.lang.Object
postProcessBeforeInitialization(java.lang.Object bean, java.lang.String beanName)
protected void
processKafkaListener(KafkaListener kafkaListener, java.lang.reflect.Method method, java.lang.Object bean, java.lang.String beanName)
protected void
processListener(MethodKafkaListenerEndpoint<?,?> endpoint, KafkaListener kafkaListener, java.lang.Object bean, java.lang.String beanName, java.lang.String[] topics, TopicPartitionOffset[] tps)
void
setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
void
setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
Making aBeanFactory
available is optional; if not set,KafkaListenerConfigurer
beans won't get autodetected and anendpoint registry
has to be explicitly configured.void
setCharset(java.nio.charset.Charset charset)
Set a charset to use when converting byte[] to String in method arguments and other String/byte[] conversions.void
setDefaultContainerFactoryBeanName(java.lang.String containerFactoryBeanName)
Set the name of theKafkaListenerContainerFactory
to use by default.void
setEndpointRegistry(KafkaListenerEndpointRegistry endpointRegistry)
Set theKafkaListenerEndpointRegistry
that will hold the created endpoint and manage the lifecycle of the related listener container.void
setMessageHandlerMethodFactory(org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory messageHandlerMethodFactory)
Set theMessageHandlerMethodFactory
to use to configure the message listener responsible to serve an endpoint detected by this processor.
-
-
-
Field Detail
-
DEFAULT_KAFKA_LISTENER_CONTAINER_FACTORY_BEAN_NAME
public static final java.lang.String DEFAULT_KAFKA_LISTENER_CONTAINER_FACTORY_BEAN_NAME
The bean name of the defaultKafkaListenerContainerFactory
.- See Also:
- Constant Field Values
-
-
Method Detail
-
getOrder
public int getOrder()
- Specified by:
getOrder
in interfaceorg.springframework.core.Ordered
-
setEndpointRegistry
public void setEndpointRegistry(KafkaListenerEndpointRegistry endpointRegistry)
Set theKafkaListenerEndpointRegistry
that will hold the created endpoint and manage the lifecycle of the related listener container.- Parameters:
endpointRegistry
- theKafkaListenerEndpointRegistry
to set.
-
setDefaultContainerFactoryBeanName
public void setDefaultContainerFactoryBeanName(java.lang.String containerFactoryBeanName)
Set the name of theKafkaListenerContainerFactory
to use by default.If none is specified, "kafkaListenerContainerFactory" is assumed to be defined.
- Parameters:
containerFactoryBeanName
- theKafkaListenerContainerFactory
bean name.
-
setMessageHandlerMethodFactory
public void setMessageHandlerMethodFactory(org.springframework.messaging.handler.annotation.support.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.
-
getMessageHandlerMethodFactory
public org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory getMessageHandlerMethodFactory()
Return the configured handler factory.- Returns:
- the factory.
- Since:
- 2.5.7
-
getEndpointRegistrar
public KafkaListenerEndpointRegistrar getEndpointRegistrar()
Return theKafkaListenerEndpointRegistrar
.- Returns:
- the registrar.
- Since:
- 2.9.3
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
- Specified by:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
- Throws:
org.springframework.beans.BeansException
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
Making aBeanFactory
available is optional; if not set,KafkaListenerConfigurer
beans won't get autodetected and anendpoint registry
has to be explicitly configured.- Parameters:
beanFactory
- theBeanFactory
to be used.
-
setCharset
public void setCharset(java.nio.charset.Charset charset)
Set a charset to use when converting byte[] to String in method arguments and other String/byte[] conversions. Default UTF-8.- Parameters:
charset
- the charset.- Since:
- 2.2
-
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
java.lang.Exception
-
afterSingletonsInstantiated
public void afterSingletonsInstantiated()
- Specified by:
afterSingletonsInstantiated
in interfaceorg.springframework.beans.factory.SmartInitializingSingleton
-
postProcessBeforeInitialization
public java.lang.Object postProcessBeforeInitialization(java.lang.Object bean, java.lang.String beanName) throws org.springframework.beans.BeansException
- Specified by:
postProcessBeforeInitialization
in interfaceorg.springframework.beans.factory.config.BeanPostProcessor
- Throws:
org.springframework.beans.BeansException
-
postProcessAfterInitialization
public java.lang.Object postProcessAfterInitialization(java.lang.Object bean, java.lang.String beanName) throws org.springframework.beans.BeansException
- Specified by:
postProcessAfterInitialization
in interfaceorg.springframework.beans.factory.config.BeanPostProcessor
- Throws:
org.springframework.beans.BeansException
-
processKafkaListener
protected void processKafkaListener(KafkaListener kafkaListener, java.lang.reflect.Method method, java.lang.Object bean, java.lang.String beanName)
-
processListener
protected void processListener(MethodKafkaListenerEndpoint<?,?> endpoint, KafkaListener kafkaListener, java.lang.Object bean, java.lang.String beanName, java.lang.String[] topics, TopicPartitionOffset[] tps)
-
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)
-
-