Example usage for org.springframework.amqp.rabbit.annotation RabbitListenerConfigurer configureRabbitListeners

List of usage examples for org.springframework.amqp.rabbit.annotation RabbitListenerConfigurer configureRabbitListeners

Introduction

In this page you can find the example usage for org.springframework.amqp.rabbit.annotation RabbitListenerConfigurer configureRabbitListeners.

Prototype

void configureRabbitListeners(RabbitListenerEndpointRegistrar registrar);

Source Link

Document

Callback allowing a org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry RabbitListenerEndpointRegistry and specific org.springframework.amqp.rabbit.listener.RabbitListenerEndpoint RabbitListenerEndpoint instances to be registered against the given RabbitListenerEndpointRegistrar .

Usage

From source file:org.springframework.amqp.rabbit.annotation.RabbitListenerAnnotationBeanPostProcessor.java

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

    if (this.beanFactory instanceof ListableBeanFactory) {
        Map<String, RabbitListenerConfigurer> instances = ((ListableBeanFactory) this.beanFactory)
                .getBeansOfType(RabbitListenerConfigurer.class);
        for (RabbitListenerConfigurer configurer : instances.values()) {
            configurer.configureRabbitListeners(this.registrar);
        }/*ww  w  .j a v  a  2 s  . co  m*/
    }

    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(
                    RabbitListenerConfigUtils.RABBIT_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME,
                    RabbitListenerEndpointRegistry.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();
}