From 1d1302acdfaef7734d513fc04a1ad2a08a6deac0 Mon Sep 17 00:00:00 2001 From: Josh Long Date: Tue, 17 Aug 2010 23:06:15 +0000 Subject: [PATCH] Adding support for alternatively injecting a simple MessageChannel reference --- .../config/ConsumerEndpointFactoryBean.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java index 42b4da5f50..c1bafa5913 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java @@ -39,10 +39,12 @@ import org.springframework.integration.endpoint.PollingConsumer; import org.springframework.integration.history.MessageHistoryWriter; import org.springframework.integration.scheduling.PollerMetadata; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; /** * @author Mark Fisher * @author Oleg Zhurakousky + * @author Josh Long */ public class ConsumerEndpointFactoryBean implements FactoryBean, BeanFactoryAware, BeanNameAware, InitializingBean, SmartLifecycle { @@ -57,7 +59,9 @@ public class ConsumerEndpointFactoryBean private volatile boolean autoStartup = true; - private volatile ConfigurableBeanFactory beanFactory; + private volatile MessageChannel inputChannel; + + private volatile ConfigurableBeanFactory beanFactory; private volatile AbstractEndpoint endpoint; @@ -67,7 +71,6 @@ public class ConsumerEndpointFactoryBean private final Object handlerMonitor = new Object(); - public void setHandler(MessageHandler handler) { Assert.notNull(handler, "handler must not be null"); synchronized (this.handlerMonitor) { @@ -76,6 +79,9 @@ public class ConsumerEndpointFactoryBean } } + public void setInputChannel(MessageChannel inputChannel) { + this.inputChannel= inputChannel; + } public void setInputChannelName(String inputChannelName) { this.inputChannelName = inputChannelName; @@ -136,10 +142,22 @@ public class ConsumerEndpointFactoryBean if (this.initialized) { return; } - Assert.hasText(this.inputChannelName, "inputChannelName is required"); - Assert.isTrue(this.beanFactory.containsBean(this.inputChannelName), + + + + MessageChannel channel = null; + + if(StringUtils.hasText(this.inputChannelName)) { + Assert.isTrue(this.beanFactory.containsBean(this.inputChannelName), "no such input channel '" + this.inputChannelName + "' for endpoint '" + this.beanName + "'"); - MessageChannel channel = this.beanFactory.getBean(this.inputChannelName, MessageChannel.class); + channel = this.beanFactory.getBean(this.inputChannelName, MessageChannel.class); + } + if( this.inputChannel != null ){ + channel = this.inputChannel; + } + + Assert.state( channel != null , "one of inputChannelName or inputChannel is required"); + if (channel instanceof SubscribableChannel) { Assert.isNull(this.pollerMetadata, "A poller should not be specified for endpoint '" + this.beanName + "', since '" + this.inputChannelName + "' is a SubscribableChannel (not pollable).");