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;
}
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;
}
Aggregations