Removed support for 'auto-create-channels' on the MessageBus. All channels must be explicitly created and registered with the bus (INT-247).
This commit is contained in:
@@ -7,7 +7,10 @@
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<message-bus auto-create-channels="true"/>
|
||||
<message-bus/>
|
||||
|
||||
<channel id="inputChannel"/>
|
||||
<channel id="outputChannel"/>
|
||||
|
||||
<service-activator input-channel="inputChannel"
|
||||
output-channel="outputChannel"
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
<beans:import resource="classpath:org/springframework/integration/security/config/commonSecurityConfiguration.xml"/>
|
||||
|
||||
<message-bus auto-create-channels="false" />
|
||||
<message-bus/>
|
||||
|
||||
<si-security:secured-channels send-access="ROLE_ADMIN">
|
||||
<si-security:channel-name-pattern>secured.*</si-security:channel-name-pattern>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
http://www.springframework.org/schema/integration-security http://www.springframework.org/schema/integration/spring-integration-security-1.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<message-bus auto-create-channels="false" />
|
||||
<message-bus/>
|
||||
|
||||
<direct-channel id="input"/>
|
||||
|
||||
|
||||
@@ -96,8 +96,6 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
|
||||
|
||||
private volatile boolean configureAsyncEventMulticaster = false;
|
||||
|
||||
private volatile boolean autoCreateChannels = false;
|
||||
|
||||
private volatile boolean autoStartup = true;
|
||||
|
||||
private volatile boolean initialized;
|
||||
@@ -146,14 +144,6 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
|
||||
this.autoStartup = autoStartup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether the bus should automatically create a channel when a
|
||||
* subscription contains the name of a previously unregistered channel.
|
||||
*/
|
||||
public void setAutoCreateChannels(boolean autoCreateChannels) {
|
||||
this.autoCreateChannels = autoCreateChannels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether the bus should configure its asynchronous task executor
|
||||
* to also be used by the ApplicationContext's 'applicationEventMulticaster'.
|
||||
@@ -297,15 +287,25 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
|
||||
}
|
||||
MessageTarget target = endpoint.getTarget();
|
||||
if (target == null) {
|
||||
target = this.lookupOrCreateChannel(endpoint.getOutputChannelName());
|
||||
if (target != null) {
|
||||
String outputChannelName = endpoint.getOutputChannelName();
|
||||
if (outputChannelName != null) {
|
||||
target = this.lookupChannel(outputChannelName);
|
||||
if (target == null) {
|
||||
throw new ConfigurationException("cannot activate endpoint '" + endpoint +
|
||||
"', unable to resolve output-channel '" + outputChannelName + "'");
|
||||
}
|
||||
endpoint.setTarget(target);
|
||||
}
|
||||
}
|
||||
MessageSource<?> source = endpoint.getSource();
|
||||
if (source == null) {
|
||||
source = this.lookupOrCreateChannel(endpoint.getInputChannelName());
|
||||
if (source != null) {
|
||||
String inputChannelName = endpoint.getInputChannelName();
|
||||
if (inputChannelName != null) {
|
||||
source = this.lookupChannel(inputChannelName);
|
||||
if (source == null) {
|
||||
throw new ConfigurationException("cannot activate endpoint '" + endpoint +
|
||||
"', unable to resolve input-channel '" + inputChannelName + "'");
|
||||
}
|
||||
endpoint.setSource(source);
|
||||
}
|
||||
}
|
||||
@@ -332,25 +332,6 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
|
||||
}
|
||||
}
|
||||
|
||||
private MessageChannel lookupOrCreateChannel(String channelName) {
|
||||
if (channelName == null) {
|
||||
return null;
|
||||
}
|
||||
MessageChannel channel = this.lookupChannel(channelName);
|
||||
if (channel == null) {
|
||||
if (!this.autoCreateChannels) {
|
||||
throw new ConfigurationException("Cannot activate endpoint, unknown channel '" + channelName
|
||||
+ "'. Consider enabling the 'autoCreateChannels' option for the message bus.");
|
||||
}
|
||||
if (this.logger.isInfoEnabled()) {
|
||||
logger.info("auto-creating channel '" + channelName + "'");
|
||||
}
|
||||
channel = channelFactory.getChannel(channelName, null);
|
||||
this.registerChannel(channel);
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
|
||||
private void registerGateway(String name, MessagingGateway gateway) {
|
||||
if (gateway instanceof Lifecycle) {
|
||||
this.lifecycleEndpoints.add((Lifecycle) gateway);
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="auto-startup" type="xsd:boolean"/>
|
||||
<xsd:attribute name="auto-create-channels" type="xsd:boolean"/>
|
||||
<xsd:attribute name="channel-factory" type="xsd:string"/>
|
||||
<xsd:attribute name="dispatcher-pool-size" type="xsd:int"/>
|
||||
<xsd:attribute name="configure-async-event-multicaster" type="xsd:boolean"/>
|
||||
|
||||
@@ -81,20 +81,6 @@ public class MessageBusParserTests {
|
||||
bus.registerEndpoint(endpoint);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoCreateChannelsEnabled() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"messageBusWithAutoCreateChannels.xml", this.getClass());
|
||||
MessageBus bus = (MessageBus) context.getBean(MessageBusParser.MESSAGE_BUS_BEAN_NAME);
|
||||
DefaultEndpoint<MessageHandler> endpoint = new DefaultEndpoint<MessageHandler>(TestHandlers.nullHandler());
|
||||
endpoint.setBeanName("testEndpoint");
|
||||
endpoint.setInputChannelName("channelToCreate");
|
||||
bus.registerEndpoint(endpoint);
|
||||
bus.start();
|
||||
assertNotNull(bus.lookupChannel("channelToCreate"));
|
||||
bus.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMessageBusElements() {
|
||||
boolean exceptionThrown = false;
|
||||
|
||||
@@ -124,20 +124,6 @@ public class MessagingAnnotationPostProcessorTests {
|
||||
context.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleHandlerWithAutoCreatedChannels() throws InterruptedException {
|
||||
AbstractApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"simpleAnnotatedEndpointWithAutoCreateChannelTests.xml", this.getClass());
|
||||
context.start();
|
||||
ChannelRegistry channelRegistry = (ChannelRegistry) context.getBean("bus");
|
||||
MessageChannel inputChannel = channelRegistry.lookupChannel("inputChannel");
|
||||
PollableChannel outputChannel = (PollableChannel) channelRegistry.lookupChannel("outputChannel");
|
||||
inputChannel.send(new StringMessage("world"));
|
||||
Message<?> message = outputChannel.receive(1000);
|
||||
assertEquals("hello world", message.getPayload());
|
||||
context.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageParameterHandler() throws InterruptedException {
|
||||
AbstractApplicationContext context = new ClassPathXmlApplicationContext("messageParameterAnnotatedEndpointTests.xml", this.getClass());
|
||||
@@ -222,50 +208,62 @@ public class MessagingAnnotationPostProcessorTests {
|
||||
@Test
|
||||
public void testProxiedMessageEndpointAnnotation() {
|
||||
DefaultMessageBus messageBus = new DefaultMessageBus();
|
||||
messageBus.setAutoCreateChannels(true);
|
||||
QueueChannel inputChannel = new QueueChannel();
|
||||
QueueChannel outputChannel = new QueueChannel();
|
||||
inputChannel.setBeanName("inputChannel");
|
||||
outputChannel.setBeanName("outputChannel");
|
||||
messageBus.registerChannel(inputChannel);
|
||||
messageBus.registerChannel(outputChannel);
|
||||
MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor(messageBus);
|
||||
postProcessor.afterPropertiesSet();
|
||||
ProxyFactory proxyFactory = new ProxyFactory(new SimpleAnnotatedEndpoint());
|
||||
Object proxy = proxyFactory.getProxy();
|
||||
postProcessor.postProcessAfterInitialization(proxy, "proxy");
|
||||
messageBus.start();
|
||||
MessageChannel inputChannel = messageBus.lookupChannel("inputChannel");
|
||||
PollableChannel outputChannel = (PollableChannel) messageBus.lookupChannel("outputChannel");
|
||||
inputChannel.send(new StringMessage("world"));
|
||||
Message<?> message = outputChannel.receive(1000);
|
||||
assertEquals("hello world", message.getPayload());
|
||||
messageBus.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageEndpointAnnotationInherited() {
|
||||
DefaultMessageBus messageBus = new DefaultMessageBus();
|
||||
messageBus.setAutoCreateChannels(true);
|
||||
QueueChannel inputChannel = new QueueChannel();
|
||||
QueueChannel outputChannel = new QueueChannel();
|
||||
inputChannel.setBeanName("inputChannel");
|
||||
outputChannel.setBeanName("outputChannel");
|
||||
messageBus.registerChannel(inputChannel);
|
||||
messageBus.registerChannel(outputChannel);
|
||||
MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor(messageBus);
|
||||
postProcessor.afterPropertiesSet();
|
||||
postProcessor.postProcessAfterInitialization(new SimpleAnnotatedEndpointSubclass(), "subclass");
|
||||
messageBus.start();
|
||||
MessageChannel inputChannel = messageBus.lookupChannel("inputChannel");
|
||||
PollableChannel outputChannel = (PollableChannel) messageBus.lookupChannel("outputChannel");
|
||||
inputChannel.send(new StringMessage("world"));
|
||||
Message<?> message = outputChannel.receive(1000);
|
||||
assertEquals("hello world", message.getPayload());
|
||||
messageBus.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageEndpointAnnotationInheritedWithProxy() {
|
||||
DefaultMessageBus messageBus = new DefaultMessageBus();
|
||||
messageBus.setAutoCreateChannels(true);
|
||||
QueueChannel inputChannel = new QueueChannel();
|
||||
QueueChannel outputChannel = new QueueChannel();
|
||||
inputChannel.setBeanName("inputChannel");
|
||||
outputChannel.setBeanName("outputChannel");
|
||||
messageBus.registerChannel(inputChannel);
|
||||
messageBus.registerChannel(outputChannel);
|
||||
MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor(messageBus);
|
||||
postProcessor.afterPropertiesSet();
|
||||
ProxyFactory proxyFactory = new ProxyFactory(new SimpleAnnotatedEndpointSubclass());
|
||||
Object proxy = proxyFactory.getProxy();
|
||||
postProcessor.postProcessAfterInitialization(proxy, "proxy");
|
||||
messageBus.start();
|
||||
MessageChannel inputChannel = messageBus.lookupChannel("inputChannel");
|
||||
PollableChannel outputChannel = (PollableChannel) messageBus.lookupChannel("outputChannel");
|
||||
inputChannel.send(new StringMessage("world"));
|
||||
Message<?> message = outputChannel.receive(1000);
|
||||
assertEquals("hello world", message.getPayload());
|
||||
messageBus.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -284,21 +282,26 @@ public class MessagingAnnotationPostProcessorTests {
|
||||
inputChannel.send(new StringMessage("ABC"));
|
||||
Message<?> message = outputChannel.receive(1000);
|
||||
assertEquals("test-ABC", message.getPayload());
|
||||
messageBus.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageEndpointAnnotationInheritedFromInterfaceWithAutoCreatedChannels() {
|
||||
DefaultMessageBus messageBus = new DefaultMessageBus();
|
||||
messageBus.setAutoCreateChannels(true);
|
||||
QueueChannel inputChannel = new QueueChannel();
|
||||
QueueChannel outputChannel = new QueueChannel();
|
||||
inputChannel.setBeanName("inputChannel");
|
||||
outputChannel.setBeanName("outputChannel");
|
||||
messageBus.registerChannel(inputChannel);
|
||||
messageBus.registerChannel(outputChannel);
|
||||
MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor(messageBus);
|
||||
postProcessor.afterPropertiesSet();
|
||||
postProcessor.postProcessAfterInitialization(new SimpleAnnotatedEndpointImplementation(), "impl");
|
||||
messageBus.start();
|
||||
MessageChannel inputChannel = messageBus.lookupChannel("inputChannel");
|
||||
PollableChannel outputChannel = (PollableChannel) messageBus.lookupChannel("outputChannel");
|
||||
inputChannel.send(new StringMessage("ABC"));
|
||||
Message<?> message = outputChannel.receive(1000);
|
||||
assertEquals("test-ABC", message.getPayload());
|
||||
messageBus.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -319,6 +322,7 @@ public class MessagingAnnotationPostProcessorTests {
|
||||
inputChannel.send(new StringMessage("ABC"));
|
||||
Message<?> message = outputChannel.receive(1000);
|
||||
assertEquals("test-ABC", message.getPayload());
|
||||
messageBus.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -349,6 +353,7 @@ public class MessagingAnnotationPostProcessorTests {
|
||||
assertNotNull(message4);
|
||||
assertEquals("test", message4.getPayload());
|
||||
assertNull(output.receive(500));
|
||||
messageBus.stop();
|
||||
}
|
||||
|
||||
@Test(expected=ConfigurationException.class)
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<bean id="bus" class="org.springframework.integration.bus.DefaultMessageBus">
|
||||
<property name="autoCreateChannels" value="true"/>
|
||||
</bean>
|
||||
|
||||
<bean id="endpoint" class="org.springframework.integration.config.annotation.SimpleAnnotatedEndpoint"/>
|
||||
|
||||
<bean class="org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor">
|
||||
<constructor-arg ref="bus"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd">
|
||||
|
||||
<message-bus auto-create-channels="true"/>
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user