INT-1998 refactored AmqpInboundGateway to be compatible with latest parser changes
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user