Search in sources :

Example 1 with RabbitListenerContainerFactory

use of org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory in project spring-amqp by spring-projects.

the class RabbitListenerAnnotationBeanPostProcessor method resolveContainerFactory.

@Nullable
private RabbitListenerContainerFactory<?> resolveContainerFactory(RabbitListener rabbitListener, Object factoryTarget, String beanName) {
    RabbitListenerContainerFactory<?> factory = null;
    Object resolved = resolveExpression(rabbitListener.containerFactory());
    if (resolved instanceof RabbitListenerContainerFactory) {
        return (RabbitListenerContainerFactory<?>) resolved;
    }
    String containerFactoryBeanName = resolveExpressionAsString(rabbitListener.containerFactory(), "containerFactory");
    if (StringUtils.hasText(containerFactoryBeanName)) {
        assertBeanFactory();
        try {
            factory = this.beanFactory.getBean(containerFactoryBeanName, RabbitListenerContainerFactory.class);
        } catch (NoSuchBeanDefinitionException ex) {
            throw new BeanInitializationException(noBeanFoundMessage(factoryTarget, beanName, containerFactoryBeanName, RabbitListenerContainerFactory.class), ex);
        }
    }
    return factory;
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) RabbitListenerContainerFactory(org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Nullable(org.springframework.lang.Nullable)

Example 2 with RabbitListenerContainerFactory

use of org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory in project spring-amqp by spring-projects.

the class RabbitListenerAnnotationBeanPostProcessor method processListener.

protected Collection<Declarable> processListener(MethodRabbitListenerEndpoint endpoint, RabbitListener rabbitListener, Object bean, Object target, String beanName) {
    final List<Declarable> declarables = new ArrayList<>();
    endpoint.setBean(bean);
    endpoint.setMessageHandlerMethodFactory(this.messageHandlerMethodFactory);
    endpoint.setId(getEndpointId(rabbitListener));
    List<Object> resolvedQueues = resolveQueues(rabbitListener, declarables);
    if (!resolvedQueues.isEmpty()) {
        if (resolvedQueues.get(0) instanceof String) {
            endpoint.setQueueNames(resolvedQueues.stream().map(o -> (String) o).collect(Collectors.toList()).toArray(new String[0]));
        } else {
            endpoint.setQueues(resolvedQueues.stream().map(o -> (Queue) o).collect(Collectors.toList()).toArray(new Queue[0]));
        }
    }
    endpoint.setConcurrency(resolveExpressionAsStringOrInteger(rabbitListener.concurrency(), "concurrency"));
    endpoint.setBeanFactory(this.beanFactory);
    endpoint.setReturnExceptions(resolveExpressionAsBoolean(rabbitListener.returnExceptions()));
    resolveErrorHandler(endpoint, rabbitListener);
    String group = rabbitListener.group();
    if (StringUtils.hasText(group)) {
        Object resolvedGroup = resolveExpression(group);
        if (resolvedGroup instanceof String) {
            endpoint.setGroup((String) resolvedGroup);
        }
    }
    String autoStartup = rabbitListener.autoStartup();
    if (StringUtils.hasText(autoStartup)) {
        endpoint.setAutoStartup(resolveExpressionAsBoolean(autoStartup));
    }
    endpoint.setExclusive(rabbitListener.exclusive());
    String priority = resolveExpressionAsString(rabbitListener.priority(), "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);
        }
    }
    resolveExecutor(endpoint, rabbitListener, target, beanName);
    resolveAdmin(endpoint, rabbitListener, target);
    resolveAckMode(endpoint, rabbitListener);
    resolvePostProcessor(endpoint, rabbitListener, target, beanName);
    resolveMessageConverter(endpoint, rabbitListener, target, beanName);
    resolveReplyContentType(endpoint, rabbitListener);
    RabbitListenerContainerFactory<?> factory = resolveContainerFactory(rabbitListener, target, beanName);
    this.registrar.registerEndpoint(endpoint, factory);
    return declarables;
}
Also used : Arrays(java.util.Arrays) AopUtils(org.springframework.aop.support.AopUtils) Validator(org.springframework.validation.Validator) MethodRabbitListenerEndpoint(org.springframework.amqp.rabbit.listener.MethodRabbitListenerEndpoint) RabbitListenerEndpointRegistrar(org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistrar) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) RabbitListenerEndpointRegistry(org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry) MergedAnnotations(org.springframework.core.annotation.MergedAnnotations) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) TaskExecutor(org.springframework.core.task.TaskExecutor) Method(java.lang.reflect.Method) ClassUtils(org.springframework.util.ClassUtils) ExchangeTypes(org.springframework.amqp.core.ExchangeTypes) Collection(java.util.Collection) MessageConverter(org.springframework.amqp.support.converter.MessageConverter) AnnotationUtils(org.springframework.core.annotation.AnnotationUtils) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) BeanPostProcessor(org.springframework.beans.factory.config.BeanPostProcessor) List(java.util.List) Environment(org.springframework.core.env.Environment) CollectionUtils(org.springframework.util.CollectionUtils) LogFactory(org.apache.commons.logging.LogFactory) Binding(org.springframework.amqp.core.Binding) BeanClassLoaderAware(org.springframework.beans.factory.BeanClassLoaderAware) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) AnnotatedElement(java.lang.reflect.AnnotatedElement) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) ReplyPostProcessor(org.springframework.amqp.rabbit.listener.adapter.ReplyPostProcessor) Ordered(org.springframework.core.Ordered) HandlerMethodArgumentResolver(org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver) InvocableHandlerMethod(org.springframework.messaging.handler.invocation.InvocableHandlerMethod) DestinationType(org.springframework.amqp.core.Binding.DestinationType) Advised(org.springframework.aop.framework.Advised) StandardBeanExpressionResolver(org.springframework.context.expression.StandardBeanExpressionResolver) Base64UrlNamingStrategy(org.springframework.amqp.core.Base64UrlNamingStrategy) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) AmqpAdmin(org.springframework.amqp.core.AmqpAdmin) HashSet(java.util.HashSet) Charset(java.nio.charset.Charset) RabbitListenerConfigUtils(org.springframework.amqp.rabbit.config.RabbitListenerConfigUtils) Queue(org.springframework.amqp.core.Queue) BeanFactoryAware(org.springframework.beans.factory.BeanFactoryAware) DefaultMessageHandlerMethodFactory(org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory) RabbitAdmin(org.springframework.amqp.rabbit.core.RabbitAdmin) Nullable(org.springframework.lang.Nullable) ConversionService(org.springframework.core.convert.ConversionService) ExchangeBuilder(org.springframework.amqp.core.ExchangeBuilder) SearchStrategy(org.springframework.core.annotation.MergedAnnotations.SearchStrategy) Converter(org.springframework.core.convert.converter.Converter) RabbitListenerErrorHandler(org.springframework.amqp.rabbit.listener.api.RabbitListenerErrorHandler) RabbitListenerContainerFactory(org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory) MultiMethodRabbitListenerEndpoint(org.springframework.amqp.rabbit.listener.MultiMethodRabbitListenerEndpoint) Declarable(org.springframework.amqp.core.Declarable) BeansException(org.springframework.beans.BeansException) BeanExpressionContext(org.springframework.beans.factory.config.BeanExpressionContext) SmartInitializingSingleton(org.springframework.beans.factory.SmartInitializingSingleton) MessageHandlerMethodFactory(org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory) EnvironmentAware(org.springframework.context.EnvironmentAware) ReflectionUtils(org.springframework.util.ReflectionUtils) BeanFactory(org.springframework.beans.factory.BeanFactory) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Log(org.apache.commons.logging.Log) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Collections(java.util.Collections) AcknowledgeMode(org.springframework.amqp.core.AcknowledgeMode) BeanExpressionResolver(org.springframework.beans.factory.config.BeanExpressionResolver) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) Declarable(org.springframework.amqp.core.Declarable) ArrayList(java.util.ArrayList) Queue(org.springframework.amqp.core.Queue)

Aggregations

RabbitListenerContainerFactory (org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory)2 BeanInitializationException (org.springframework.beans.factory.BeanInitializationException)2 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)2 Nullable (org.springframework.lang.Nullable)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Method (java.lang.reflect.Method)1 Charset (java.nio.charset.Charset)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1