INT-2277: Register ChResolver & ErrHandler beans (#2805)
* INT-2277: Register ChResolver & ErrHandler beans JIRA: https://jira.spring.io/browse/INT-2277 To avoid extra objects at runtime and reuse a central configuration, register `BeanFactoryChannelResolver` and `MessagePublishingErrorHandler` bean via `DefaultConfiguringBeanFactoryPostProcessor` * Use those beans whenever it is necessary via `IntegrationContextUtils` factory methods against provided `BeanFactory` * To avoid changes in the non-managed test, those new factories fall back to a new instance if there is no an appropriate bean in the `beanFactory` * * Add `Assert.notNull(beanFactory)` to new factory methods
This commit is contained in:
committed by
Gary Russell
parent
14c67421ef
commit
9883b65e94
@@ -18,6 +18,7 @@ package org.springframework.integration.redis.channel;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
@@ -32,10 +33,9 @@ import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.integration.MessageDispatchingException;
|
||||
import org.springframework.integration.channel.AbstractMessageChannel;
|
||||
import org.springframework.integration.channel.MessagePublishingErrorHandler;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.context.IntegrationProperties;
|
||||
import org.springframework.integration.dispatcher.BroadcastingDispatcher;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.support.converter.SimpleMessageConverter;
|
||||
import org.springframework.integration.util.ErrorHandlingTaskExecutor;
|
||||
import org.springframework.messaging.Message;
|
||||
@@ -143,13 +143,13 @@ public class SubscribableRedisChannel extends AbstractMessageChannel
|
||||
if (this.messageConverter == null) {
|
||||
this.messageConverter = new SimpleMessageConverter();
|
||||
}
|
||||
BeanFactory beanFactory = getBeanFactory();
|
||||
if (this.messageConverter instanceof BeanFactoryAware) {
|
||||
((BeanFactoryAware) this.messageConverter).setBeanFactory(this.getBeanFactory());
|
||||
((BeanFactoryAware) this.messageConverter).setBeanFactory(beanFactory);
|
||||
}
|
||||
this.container.setConnectionFactory(this.connectionFactory);
|
||||
if (!(this.taskExecutor instanceof ErrorHandlingTaskExecutor)) {
|
||||
ErrorHandler errorHandler = new MessagePublishingErrorHandler(
|
||||
new BeanFactoryChannelResolver(this.getBeanFactory()));
|
||||
ErrorHandler errorHandler = IntegrationContextUtils.getErrorHandler(beanFactory);
|
||||
this.taskExecutor = new ErrorHandlingTaskExecutor(this.taskExecutor, errorHandler);
|
||||
}
|
||||
this.container.setTaskExecutor(this.taskExecutor);
|
||||
@@ -158,7 +158,7 @@ public class SubscribableRedisChannel extends AbstractMessageChannel
|
||||
adapter.afterPropertiesSet();
|
||||
this.container.addMessageListener(adapter, new ChannelTopic(this.topicName));
|
||||
this.container.afterPropertiesSet();
|
||||
this.dispatcher.setBeanFactory(this.getBeanFactory());
|
||||
this.dispatcher.setBeanFactory(beanFactory);
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2018 the original author or authors.
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,7 +31,6 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.integration.channel.MessagePublishingErrorHandler;
|
||||
import org.springframework.integration.gateway.MessagingGatewaySupport;
|
||||
import org.springframework.integration.redis.event.RedisExceptionEvent;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.support.management.IntegrationManagedResource;
|
||||
import org.springframework.integration.util.ErrorHandlingTaskExecutor;
|
||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||
@@ -152,8 +151,8 @@ public class RedisQueueInboundGateway extends MessagingGatewaySupport implements
|
||||
+ this.getComponentType());
|
||||
}
|
||||
if (!(this.taskExecutor instanceof ErrorHandlingTaskExecutor) && this.getBeanFactory() != null) {
|
||||
MessagePublishingErrorHandler errorHandler =
|
||||
new MessagePublishingErrorHandler(new BeanFactoryChannelResolver(getBeanFactory()));
|
||||
MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler();
|
||||
errorHandler.setBeanFactory(getBeanFactory());
|
||||
errorHandler.setDefaultErrorChannel(getErrorChannel());
|
||||
this.taskExecutor = new ErrorHandlingTaskExecutor(this.taskExecutor, errorHandler);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
* Copyright 2013-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@ import java.util.Optional;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
@@ -30,9 +31,9 @@ import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.integration.channel.MessagePublishingErrorHandler;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.endpoint.MessageProducerSupport;
|
||||
import org.springframework.integration.redis.event.RedisExceptionEvent;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.support.management.IntegrationManagedResource;
|
||||
import org.springframework.integration.util.ErrorHandlingTaskExecutor;
|
||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||
@@ -169,13 +170,14 @@ public class RedisQueueMessageDrivenEndpoint extends MessageProducerSupport impl
|
||||
Assert.notNull(this.serializer, "'serializer' has to be provided where 'expectMessage == true'.");
|
||||
}
|
||||
if (this.taskExecutor == null) {
|
||||
String beanName = this.getComponentName();
|
||||
String beanName = getComponentName();
|
||||
this.taskExecutor = new SimpleAsyncTaskExecutor((beanName == null ? "" : beanName + "-")
|
||||
+ this.getComponentType());
|
||||
+ getComponentType());
|
||||
}
|
||||
if (!(this.taskExecutor instanceof ErrorHandlingTaskExecutor) && this.getBeanFactory() != null) {
|
||||
BeanFactory beanFactory = getBeanFactory();
|
||||
if (!(this.taskExecutor instanceof ErrorHandlingTaskExecutor) && beanFactory != null) {
|
||||
MessagePublishingErrorHandler errorHandler =
|
||||
new MessagePublishingErrorHandler(new BeanFactoryChannelResolver(this.getBeanFactory()));
|
||||
new MessagePublishingErrorHandler(IntegrationContextUtils.getChannelResolver(beanFactory));
|
||||
errorHandler.setDefaultErrorChannel(this.errorChannel);
|
||||
this.taskExecutor = new ErrorHandlingTaskExecutor(this.taskExecutor, errorHandler);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user