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 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 with KafkaListener to be invoked by a Kafka message listener container created under the covers by a KafkaListenerContainerFactory 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. See EnableKafka Javadoc for complete usage details.

See Also:
  • Field Details

  • Constructor Details

    • KafkaListenerAnnotationBeanPostProcessor

      public KafkaListenerAnnotationBeanPostProcessor()
  • Method Details

    • getOrder

      public int getOrder()
      Specified by:
      getOrder in interface org.springframework.core.Ordered
    • setEndpointRegistry

      public void setEndpointRegistry(KafkaListenerEndpointRegistry endpointRegistry)
      Set the KafkaListenerEndpointRegistry that will hold the created endpoint and manage the lifecycle of the related listener container.
      Parameters:
      endpointRegistry - the KafkaListenerEndpointRegistry to set.
    • setDefaultContainerFactoryBeanName

      public void setDefaultContainerFactoryBeanName(String containerFactoryBeanName)
      Set the name of the KafkaListenerContainerFactory to use by default.

      If none is specified, "kafkaListenerContainerFactory" is assumed to be defined.

      Parameters:
      containerFactoryBeanName - the KafkaListenerContainerFactory bean name.
    • setMessageHandlerMethodFactory

      public void setMessageHandlerMethodFactory(org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory messageHandlerMethodFactory)
      Set the MessageHandlerMethodFactory 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. See DefaultMessageHandlerMethodFactory Javadoc for more details.

      Parameters:
      messageHandlerMethodFactory - the MessageHandlerMethodFactory 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()
      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 interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException
    • setBeanFactory

      public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
      Making a BeanFactory available is optional; if not set, KafkaListenerConfigurer beans won't get autodetected and an endpoint registry has to be explicitly configured.
      Parameters:
      beanFactory - the BeanFactory to be used.
    • setCharset

      public void setCharset(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 Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception
    • afterSingletonsInstantiated

      public void afterSingletonsInstantiated()
      Specified by:
      afterSingletonsInstantiated in interface org.springframework.beans.factory.SmartInitializingSingleton
    • postProcessBeforeInitialization

      public Object postProcessBeforeInitialization(Object bean, String beanName) throws org.springframework.beans.BeansException
      Specified by:
      postProcessBeforeInitialization in interface org.springframework.beans.factory.config.BeanPostProcessor
      Throws:
      org.springframework.beans.BeansException
    • postProcessAfterInitialization

      public Object postProcessAfterInitialization(Object bean, String beanName) throws org.springframework.beans.BeansException
      Specified by:
      postProcessAfterInitialization in interface org.springframework.beans.factory.config.BeanPostProcessor
      Throws:
      org.springframework.beans.BeansException
    • processKafkaListener

      protected void processKafkaListener(KafkaListener kafkaListener, Method method, Object bean, String beanName)
    • processListener

      protected void processListener(MethodKafkaListenerEndpoint<?,?> endpoint, KafkaListener kafkaListener, Object bean, String beanName, String[] topics, TopicPartitionOffset[] tps)
    • assertBeanFactory

      protected void assertBeanFactory()
    • noBeanFoundMessage

      protected String noBeanFoundMessage(Object target, String listenerBeanName, String requestedBeanName, Class<?> expectedClass)