Example usage for org.springframework.kafka.annotation KafkaListenerConfigurer configureKafkaListeners

List of usage examples for org.springframework.kafka.annotation KafkaListenerConfigurer configureKafkaListeners

Introduction

In this page you can find the example usage for org.springframework.kafka.annotation KafkaListenerConfigurer configureKafkaListeners.

Prototype

void configureKafkaListeners(KafkaListenerEndpointRegistrar registrar);

Source Link

Document

Callback allowing a org.springframework.kafka.config.KafkaListenerEndpointRegistry KafkaListenerEndpointRegistry and specific org.springframework.kafka.config.KafkaListenerEndpoint KafkaListenerEndpoint instances to be registered against the given KafkaListenerEndpointRegistrar .

Usage

From source file:org.springframework.kafka.annotation.KafkaListenerAnnotationBeanPostProcessor.java

@Override
public void afterSingletonsInstantiated() {
    this.registrar.setBeanFactory(this.beanFactory);

    if (this.beanFactory instanceof ListableBeanFactory) {
        Map<String, KafkaListenerConfigurer> instances = ((ListableBeanFactory) this.beanFactory)
                .getBeansOfType(KafkaListenerConfigurer.class);
        for (KafkaListenerConfigurer configurer : instances.values()) {
            configurer.configureKafkaListeners(this.registrar);
        }/* www .  j a va 2s .c om*/
    }

    if (this.registrar.getEndpointRegistry() == null) {
        if (this.endpointRegistry == null) {
            Assert.state(this.beanFactory != null,
                    "BeanFactory must be set to find endpoint registry by bean name");
            this.endpointRegistry = this.beanFactory.getBean(
                    KafkaListenerConfigUtils.KAFKA_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME,
                    KafkaListenerEndpointRegistry.class);
        }
        this.registrar.setEndpointRegistry(this.endpointRegistry);
    }

    if (this.containerFactoryBeanName != null) {
        this.registrar.setContainerFactoryBeanName(this.containerFactoryBeanName);
    }

    // Set the custom handler method factory once resolved by the configurer
    MessageHandlerMethodFactory handlerMethodFactory = this.registrar.getMessageHandlerMethodFactory();
    if (handlerMethodFactory != null) {
        this.messageHandlerMethodFactory.setMessageHandlerMethodFactory(handlerMethodFactory);
    }

    // Actually register all listeners
    this.registrar.afterPropertiesSet();
}