MessagingAnnotationPostProcessor now registers endpoints with the MessageBus so that they may be activated even if the bus has already detected endpoint beans from the context (INT-386). For an example, see: AnnotatedEndpointActivationTests. Although it does not impact this particular scenario, a related change is that the message bus no longer registers endpoint beans after receiving the application context refresh event. Instead it will retrieve all beans from the context when start() is invoked. It maintains a set of endpoints that also includes those registered only with the bus itself (not in the application context).
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
<?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-1.0.xsd">
|
||||
|
||||
<message-bus enable-annotations="true"/>
|
||||
|
||||
<channel id="input"/>
|
||||
|
||||
<channel id="output">
|
||||
<queue capacity="10"/>
|
||||
</channel>
|
||||
|
||||
</beans:beans>
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.config.annotation;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.integration.annotation.MessageEndpoint;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.integration.bus.MessageBus;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageDeliveryException;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@MessageEndpoint
|
||||
public class AnnotatedEndpointActivationTests {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("input")
|
||||
private MessageChannel input;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("output")
|
||||
private PollableChannel output;
|
||||
|
||||
@Autowired
|
||||
private MessageBus messageBus;
|
||||
|
||||
// This has to be static because the MessageBus registers the handler
|
||||
// more than once (every time a test instance is created), but only one of
|
||||
// them will get the message.
|
||||
private static volatile int count = 0;
|
||||
|
||||
|
||||
@ServiceActivator(inputChannel = "input", outputChannel = "output")
|
||||
public String process(String message) {
|
||||
count++;
|
||||
String result = message + ": " + count;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void resetCount() {
|
||||
count = 0;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configCheck() {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendAndReceive() {
|
||||
this.input.send(new GenericMessage<String>("foo"));
|
||||
Message<?> message = this.output.receive(100);
|
||||
assertNotNull(message);
|
||||
assertEquals("foo: 1", message.getPayload());
|
||||
assertEquals(1, count);
|
||||
}
|
||||
|
||||
@Test(expected = MessageDeliveryException.class)
|
||||
public void stopMessageBus() {
|
||||
messageBus.stop();
|
||||
this.input.send(new GenericMessage<String>("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stopAndRestartMessageBus() {
|
||||
messageBus.stop();
|
||||
messageBus.start();
|
||||
this.input.send(new GenericMessage<String>("foo"));
|
||||
Message<?> message = this.output.receive(100);
|
||||
assertNotNull(message);
|
||||
assertEquals("foo: 1", message.getPayload());
|
||||
assertEquals(1, count);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user