Class KafkaListenerAnnotationBeanPostProcessor<K,V>
- Type Parameters:
K
- the key type.V
- the value type.
- All Implemented Interfaces:
Aware
,BeanPostProcessor
,SmartInitializingSingleton
,ApplicationContextAware
,Ordered
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.
- Author:
- Stephane Nicoll, Juergen Hoeller, Gary Russell, Artem Bilan, Dariusz Szablinski, Venil Noronha, Dimitri Penner, Filip Halemba, Tomaz Fernandes, Wang Zhiyang, Sanghyeok An, Soby Chacko, Omer Celik
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Post processes each set of annotation attributes. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The bean name of the defaultKafkaListenerContainerFactory
.Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
protected void
Return theKafkaListenerEndpointRegistrar
.Return the configured handler factory.int
getOrder()
protected String
noBeanFoundMessage
(Object target, String listenerBeanName, String requestedBeanName, Class<?> expectedClass) postProcessAfterInitialization
(Object bean, String beanName) postProcessBeforeInitialization
(Object bean, String beanName) protected void
processKafkaListener
(KafkaListener kafkaListener, Method method, Object bean, String beanName) protected void
processListener
(MethodKafkaListenerEndpoint<?, ?> endpoint, KafkaListener kafkaListener, Object bean, String beanName, String[] topics, TopicPartitionOffset[] tps) void
setApplicationContext
(ApplicationContext applicationContext) void
setBeanFactory
(BeanFactory beanFactory) Making aBeanFactory
available is optional; if not set,KafkaListenerConfigurer
beans won't get auto-detected and anendpoint registry
has to be explicitly configured.void
setCharset
(Charset charset) Set a charset to use when converting byte[] to String in method arguments and other String/byte[] conversions.void
setDefaultContainerFactoryBeanName
(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
(MessageHandlerMethodFactory messageHandlerMethodFactory) Set theMessageHandlerMethodFactory
to use to configure the message listener responsible to serve an endpoint detected by this processor.
-
Field Details
-
DEFAULT_KAFKA_LISTENER_CONTAINER_FACTORY_BEAN_NAME
The bean name of the defaultKafkaListenerContainerFactory
.- See Also:
-
-
Constructor Details
-
KafkaListenerAnnotationBeanPostProcessor
public KafkaListenerAnnotationBeanPostProcessor()
-
-
Method Details
-
getOrder
public int getOrder() -
setEndpointRegistry
Set theKafkaListenerEndpointRegistry
that will hold the created endpoint and manage the lifecycle of the related listener container.- Parameters:
endpointRegistry
- theKafkaListenerEndpointRegistry
to set.
-
setDefaultContainerFactoryBeanName
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
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
Return the configured handler factory.- Returns:
- the factory.
- Since:
- 2.5.7
-
getEndpointRegistrar
Return theKafkaListenerEndpointRegistrar
.- Returns:
- the registrar.
- Since:
- 2.9.3
-
setApplicationContext
- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- Throws:
BeansException
-
setBeanFactory
Making aBeanFactory
available is optional; if not set,KafkaListenerConfigurer
beans won't get auto-detected and anendpoint registry
has to be explicitly configured.- Parameters:
beanFactory
- theBeanFactory
to be used.
-
setCharset
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
-
afterSingletonsInstantiated
public void afterSingletonsInstantiated()- Specified by:
afterSingletonsInstantiated
in interfaceSmartInitializingSingleton
-
postProcessBeforeInitialization
- Specified by:
postProcessBeforeInitialization
in interfaceBeanPostProcessor
- Throws:
BeansException
-
postProcessAfterInitialization
- Specified by:
postProcessAfterInitialization
in interfaceBeanPostProcessor
- Throws:
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
-