Example usage for org.springframework.amqp.rabbit.listener MethodRabbitListenerEndpoint setExclusive

List of usage examples for org.springframework.amqp.rabbit.listener MethodRabbitListenerEndpoint setExclusive

Introduction

In this page you can find the example usage for org.springframework.amqp.rabbit.listener MethodRabbitListenerEndpoint setExclusive.

Prototype

public void setExclusive(boolean exclusive) 

Source Link

Document

Set if a single consumer in the container will have exclusive use of the queues, preventing other consumers from receiving messages from the queue(s).

Usage

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

protected void processListener(MethodRabbitListenerEndpoint endpoint, RabbitListener rabbitListener,
        Object bean, Object adminTarget, String beanName) {
    endpoint.setBean(bean);/*from  w  w  w .  j a va2s .  c  o m*/
    endpoint.setMessageHandlerMethodFactory(this.messageHandlerMethodFactory);
    endpoint.setId(getEndpointId(rabbitListener));
    endpoint.setQueueNames(resolveQueues(rabbitListener));
    String group = rabbitListener.group();
    if (StringUtils.hasText(group)) {
        Object resolvedGroup = resolveExpression(group);
        if (resolvedGroup instanceof String) {
            endpoint.setGroup((String) resolvedGroup);
        }
    }

    endpoint.setExclusive(rabbitListener.exclusive());
    String priority = resolve(rabbitListener.priority());
    if (StringUtils.hasText(priority)) {
        try {
            endpoint.setPriority(Integer.valueOf(priority));
        } catch (NumberFormatException ex) {
            throw new BeanInitializationException(
                    "Invalid priority value for " + rabbitListener + " (must be an integer)", ex);
        }
    }

    String rabbitAdmin = resolve(rabbitListener.admin());
    if (StringUtils.hasText(rabbitAdmin)) {
        Assert.state(this.beanFactory != null, "BeanFactory must be set to resolve RabbitAdmin by bean name");
        try {
            endpoint.setAdmin(this.beanFactory.getBean(rabbitAdmin, RabbitAdmin.class));
        } catch (NoSuchBeanDefinitionException ex) {
            throw new BeanInitializationException("Could not register rabbit listener endpoint on ["
                    + adminTarget + "], no " + RabbitAdmin.class.getSimpleName() + " with id '" + rabbitAdmin
                    + "' was found in the application context", ex);
        }
    }

    RabbitListenerContainerFactory<?> factory = null;
    String containerFactoryBeanName = resolve(rabbitListener.containerFactory());
    if (StringUtils.hasText(containerFactoryBeanName)) {
        Assert.state(this.beanFactory != null,
                "BeanFactory must be set to obtain container factory by bean name");
        try {
            factory = this.beanFactory.getBean(containerFactoryBeanName, RabbitListenerContainerFactory.class);
        } catch (NoSuchBeanDefinitionException ex) {
            throw new BeanInitializationException(
                    "Could not register rabbit listener endpoint on [" + adminTarget + "] for bean " + beanName
                            + ", no " + RabbitListenerContainerFactory.class.getSimpleName() + " with id '"
                            + containerFactoryBeanName + "' was found in the application context",
                    ex);
        }
    }

    this.registrar.registerEndpoint(endpoint, factory);
}