INT-1910 fixed ChannelPublishingJmsMessageListener to react to Lifecycle events of JmsMessageDrivenEndpoint

This commit is contained in:
Oleg Zhurakousky
2011-05-19 17:37:44 -04:00
parent 6d0aaa7c62
commit 8e20d845bf
4 changed files with 34 additions and 12 deletions

View File

@@ -310,6 +310,14 @@ public class ChannelPublishingJmsMessageListener
this.gatewayDelegate.afterPropertiesSet();
}
protected void start(){
this.gatewayDelegate.start();
}
protected void stop(){
this.gatewayDelegate.stop();
}
private void copyCorrelationIdFromRequestToReply(javax.jms.Message requestMessage, javax.jms.Message replyMessage) throws JMSException {
if (this.correlationKey != null) {
if (this.correlationKey.equals("JMSCorrelationID")) {

View File

@@ -63,13 +63,15 @@ public class JmsMessageDrivenEndpoint extends AbstractEndpoint implements Dispos
}
protected void doStart() {
this.listener.start();
if (!this.listenerContainer.isRunning()) {
this.listenerContainer.start();
this.listenerContainer.start();
}
}
protected void doStop() {
this.listenerContainer.stop();
this.listener.stop();
}
public void destroy() throws Exception {

View File

@@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue;
import java.util.Properties;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import org.junit.Test;
@@ -35,6 +36,7 @@ import org.springframework.integration.history.MessageHistory;
import org.springframework.integration.jms.JmsMessageDrivenEndpoint;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.jms.connection.JmsTransactionManager;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.listener.AbstractMessageListenerContainer;
import org.springframework.jms.support.destination.JmsDestinationAccessor;
@@ -343,11 +345,15 @@ public class JmsInboundGatewayParserTests {
@Test
public void gatewayWithReplyChannel() {
ActiveMqTestUtils.prepare();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"jmsGatewayWithReplyChannel.xml", this.getClass());
JmsMessageDrivenEndpoint gateway = (JmsMessageDrivenEndpoint) context.getBean("gateway");
Object replyChannel = TestUtils.getPropertyValue(gateway, "listener.gatewayDelegate.replyChannel");
assertEquals(context.getBean("replies"), replyChannel);
JmsTemplate template = new JmsTemplate(context.getBean(ConnectionFactory.class));
template.convertAndSend("testDestination", "Hello");
assertNotNull(template.receive("testReplyDestination"));
}
}

View File

@@ -10,25 +10,31 @@
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd">
<si:channel id="requests">
<si:queue capacity="1"/>
</si:channel>
<si:channel id="requests"/>
<si:channel id="replies">
<si:queue capacity="1"/>
</si:channel>
<si:channel id="replies"/>
<jms:inbound-gateway id="gateway"
request-destination-name="testDestination"
default-reply-destination="testReplyDestination"
request-channel="requests"
reply-channel="replies"/>
<si:service-activator input-channel="requests" output-channel="replies" expression="payload"/>
<bean id="connectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
<constructor-arg>
<bean class="org.springframework.integration.jms.StubConnection">
<constructor-arg value="test"/>
<bean id="testDestination" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="testDestination"/>
</bean>
<bean id="testReplyDestination" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="testReplyDestination"/>
</bean>
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost"/>
</bean>
</constructor-arg>
</property>
</bean>
</beans>