Removed the 'registerChannel' method from DefaultMessageBus; all channels must be registered within the ApplicationContext. The MessageBusParser now creates the 'errorChannel' if no bean with that name is explicitly defined rather than creating it within the DefaultMessageBus initialization.
This commit is contained in:
@@ -20,7 +20,6 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
@@ -57,8 +56,6 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private final Map<String, MessageChannel> channels = new ConcurrentHashMap<String, MessageChannel>();
|
||||
|
||||
private final Set<MessageEndpoint> endpoints = new CopyOnWriteArraySet<MessageEndpoint>();
|
||||
|
||||
private final MessageBusInterceptorsList interceptors = new MessageBusInterceptorsList();
|
||||
@@ -117,9 +114,6 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
|
||||
}
|
||||
Assert.notNull(this.applicationContext, "ApplicationContext must not be null");
|
||||
Assert.notNull(this.taskScheduler, "TaskScheduler must not be null");
|
||||
if (this.getErrorChannel() == null) {
|
||||
this.registerChannel(new DefaultErrorChannel());
|
||||
}
|
||||
this.initialized = true;
|
||||
}
|
||||
}
|
||||
@@ -129,24 +123,14 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
|
||||
}
|
||||
|
||||
public MessageChannel lookupChannel(String channelName) {
|
||||
MessageChannel channel = this.channels.get(channelName);
|
||||
if (channel == null && this.applicationContext != null && this.applicationContext.containsBean(channelName)) {
|
||||
Assert.notNull(this.applicationContext, "ApplicationContext must not be null");
|
||||
if (this.applicationContext.containsBean(channelName)) {
|
||||
Object bean = this.applicationContext.getBean(channelName);
|
||||
if (bean instanceof MessageChannel) {
|
||||
channel = (MessageChannel) bean;
|
||||
this.registerChannel(channel);
|
||||
return (MessageChannel) bean;
|
||||
}
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
|
||||
public void registerChannel(MessageChannel channel) {
|
||||
Assert.notNull(channel, "'channel' must not be null");
|
||||
Assert.notNull(channel.getName(), "channel name must not be null");
|
||||
this.channels.put(channel.getName(), channel);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("registered channel '" + channel.getName() + "'");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void registerEndpoint(MessageEndpoint endpoint) {
|
||||
|
||||
@@ -41,6 +41,8 @@ import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.bus.DefaultMessageBus;
|
||||
import org.springframework.integration.bus.MessageBus;
|
||||
import org.springframework.integration.bus.MessageBusAwareBeanPostProcessor;
|
||||
import org.springframework.integration.channel.ChannelRegistry;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor;
|
||||
import org.springframework.integration.config.annotation.PublisherAnnotationPostProcessor;
|
||||
import org.springframework.integration.scheduling.SimpleTaskScheduler;
|
||||
@@ -99,6 +101,12 @@ public class MessageBusParser extends AbstractSimpleBeanDefinitionParser {
|
||||
super.doParse(element, parserContext, builder);
|
||||
String taskSchedulerRef = element.getAttribute(TASK_SCHEDULER_ATTRIBUTE);
|
||||
TaskExecutor taskExecutor= null;
|
||||
if (!parserContext.getRegistry().containsBeanDefinition(ChannelRegistry.ERROR_CHANNEL_NAME)) {
|
||||
RootBeanDefinition errorChannelDef = new RootBeanDefinition(QueueChannel.class);
|
||||
BeanDefinitionHolder errorChannelHolder = new BeanDefinitionHolder(
|
||||
errorChannelDef, ChannelRegistry.ERROR_CHANNEL_NAME);
|
||||
BeanDefinitionReaderUtils.registerBeanDefinition(errorChannelHolder, parserContext.getRegistry());
|
||||
}
|
||||
if (StringUtils.hasText(taskSchedulerRef)) {
|
||||
builder.addPropertyReference("taskScheduler", taskSchedulerRef);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user