From 30af8e6fd4d05994737437eba6d90deda4fe7e8a Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Fri, 22 Jul 2011 18:52:58 -0400 Subject: [PATCH] INT-1998 refactored AmqpInboundGateway to be compatible with latest parser changes --- build.gradle | 1 + .../amqp/inbound/AmqpInboundGateway.java | 23 +++++++------------ .../config/OutboundGatewayTests-context.xml | 2 +- .../amqp/config/OutboundGatewayTests.java | 14 +++++------ 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/build.gradle b/build.gradle index c2d35b093d..b96f3d642a 100644 --- a/build.gradle +++ b/build.gradle @@ -171,6 +171,7 @@ project('spring-integration-amqp') { compile project(":spring-integration-core") compile "org.springframework:spring-context:$springVersion" compile "org.springframework.amqp:spring-rabbit:$springAmqpVersion" + testCompile project(":spring-integration-stream") } } diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/inbound/AmqpInboundGateway.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/inbound/AmqpInboundGateway.java index 66a44aee5f..8ef1495597 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/inbound/AmqpInboundGateway.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/inbound/AmqpInboundGateway.java @@ -23,9 +23,8 @@ import org.springframework.amqp.core.Address; import org.springframework.amqp.core.Message; import org.springframework.amqp.core.MessageListener; import org.springframework.amqp.core.MessagePostProcessor; -import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.amqp.rabbit.core.RabbitTemplate; -import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; +import org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer; import org.springframework.amqp.support.converter.SimpleMessageConverter; import org.springframework.integration.amqp.support.AmqpHeaderMapper; import org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper; @@ -44,7 +43,7 @@ import org.springframework.util.Assert; */ public class AmqpInboundGateway extends MessagingGatewaySupport { - private final SimpleMessageListenerContainer messageListenerContainer; + private final AbstractMessageListenerContainer messageListenerContainer; private final SimpleMessageConverter messageConverter = new SimpleMessageConverter(); @@ -53,27 +52,21 @@ public class AmqpInboundGateway extends MessagingGatewaySupport { private final RabbitTemplate amqpTemplate; - public AmqpInboundGateway(ConnectionFactory connectionFactory) { - Assert.notNull(connectionFactory, "ConnectionFactory must not be null"); - this.messageListenerContainer = new SimpleMessageListenerContainer(connectionFactory); + public AmqpInboundGateway(AbstractMessageListenerContainer listenerContainer) { + Assert.notNull(listenerContainer, "listenerContainer must not be null"); + Assert.isNull(listenerContainer.getMessageListener(), "The listenerContainer provided to an AMQP inbound Gateway " + + "must not have a MessageListener configured since the adapter needs to configure its own listener implementation."); + this.messageListenerContainer = listenerContainer; this.messageListenerContainer.setAutoStartup(false); - this.amqpTemplate = new RabbitTemplate(connectionFactory); + this.amqpTemplate = new RabbitTemplate(this.messageListenerContainer.getConnectionFactory()); } - public void setQueueNames(String queueName) { - this.messageListenerContainer.setQueueNames(queueName); - } - public void setHeaderMapper(AmqpHeaderMapper headerMapper) { Assert.notNull(headerMapper, "headerMapper must not be null"); this.headerMapper = headerMapper; } - public void setConcurrentConsumers(int concurrentConsumers) { - this.messageListenerContainer.setConcurrentConsumers(concurrentConsumers); - } - @Override protected void onInit() throws Exception { this.messageListenerContainer.setMessageListener(new MessageListener() { diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayTests-context.xml b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayTests-context.xml index 07c654c75c..8069985f1a 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayTests-context.xml +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayTests-context.xml @@ -5,7 +5,7 @@ xmlns:console="http://www.springframework.org/schema/integration/stream" xmlns:rabbit="http://www.springframework.org/schema/rabbit" xsi:schemaLocation="http://www.springframework.org/schema/integration/amqp http://www.springframework.org/schema/integration/amqp/spring-integration-amqp.xsd - http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd + http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayTests.java index 5f5af7d2dd..405c193290 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayTests.java @@ -20,8 +20,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import org.junit.Test; -import org.springframework.beans.factory.xml.XmlBeanFactory; -import org.springframework.core.io.ClassPathResource; + +import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.test.util.ReflectionTestUtils; /** @@ -31,18 +31,18 @@ import org.springframework.test.util.ReflectionTestUtils; */ public class OutboundGatewayTests { - private XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(getClass().getSimpleName()+"-context.xml", getClass())); + private ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); @Test public void testVanillaConfiguration() throws Exception { - assertTrue(beanFactory.containsBeanDefinition("vanilla")); - beanFactory.getBean("vanilla"); + assertTrue(context.getBeanFactory().containsBeanDefinition("vanilla")); + context.getBean("vanilla"); } @Test public void testExpressionBasedConfiguration() throws Exception { - assertTrue(beanFactory.containsBeanDefinition("expression")); - Object target = beanFactory.getBean("expression"); + assertTrue(context.getBeanFactory().containsBeanDefinition("expression")); + Object target = context.getBean("expression"); assertNotNull(ReflectionTestUtils.getField(ReflectionTestUtils.getField(target, "handler"), "routingKeyGenerator")); }