INT-3105 Add 'task-executor' to JMS MDCA

Add task-attribute to int-jms:message-driven-channel-adapter.

Polishing

Fix white space; add author tags; use class name in parser.
This commit is contained in:
Michael Bannister
2013-08-12 20:44:13 +01:00
committed by Gary Russell
parent e8ef5ab878
commit ef3feb687b
5 changed files with 72 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2013 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.
@@ -25,13 +25,15 @@ import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.integration.jms.JmsMessageDrivenEndpoint;
import org.springframework.util.StringUtils;
/**
* Parser for the <message-driven-channel-adapter> element and the
* <inbound-gateway> element of the 'jms' namespace.
*
*
* @author Mark Fisher
* @author Michael Bannister
*/
public class JmsMessageDrivenEndpointParser extends AbstractSingleBeanDefinitionParser {
@@ -60,7 +62,7 @@ public class JmsMessageDrivenEndpointParser extends AbstractSingleBeanDefinition
"receive-timeout", "recovery-interval",
"idle-consumer-limit", "idle-task-execution-limit",
"cache-level", "subscription-durable", "durable-subscription-name",
"client-id"
"client-id", "task-executor"
};
@@ -74,7 +76,7 @@ public class JmsMessageDrivenEndpointParser extends AbstractSingleBeanDefinition
@Override
protected String getBeanClassName(Element element) {
return "org.springframework.integration.jms.JmsMessageDrivenEndpoint";
return JmsMessageDrivenEndpoint.class.getName();
}
@Override
@@ -141,6 +143,7 @@ public class JmsMessageDrivenEndpointParser extends AbstractSingleBeanDefinition
}
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "destination-resolver");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "transaction-manager");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "task-executor");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "selector", "messageSelector");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "concurrent-consumers");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "max-concurrent-consumers");
@@ -203,7 +206,7 @@ public class JmsMessageDrivenEndpointParser extends AbstractSingleBeanDefinition
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "header-mapper");
BeanDefinition beanDefinition = builder.getBeanDefinition();
String beanName = BeanDefinitionReaderUtils.generateBeanName(beanDefinition, parserContext.getRegistry());
BeanComponentDefinition component = new BeanComponentDefinition(beanDefinition, beanName);
BeanComponentDefinition component = new BeanComponentDefinition(beanDefinition, beanName);
parserContext.registerBeanComponent(component);
return beanName;
}

View File

@@ -441,6 +441,19 @@
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="task-executor" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
A reference to a Spring TaskExecutor (or standard JDK 1.5+ Executor) for running the listener threads.
Default for the message listener container is a SimpleAsyncTaskExecutor.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="java.util.concurrent.Executor"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2013 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.
@@ -18,6 +18,7 @@ package org.springframework.integration.jms.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import java.util.Properties;
@@ -36,6 +37,7 @@ import org.springframework.jms.support.destination.JmsDestinationAccessor;
/**
* @author Mark Fisher
* @author Michael Bannister
*/
public class JmsMessageDrivenChannelAdapterParserTests {
@@ -81,6 +83,17 @@ public class JmsMessageDrivenChannelAdapterParserTests {
endpoint.stop();
}
@Test
public void adapterWithTaskExecutor() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"jmsInboundWithTaskExecutor.xml", this.getClass());
JmsMessageDrivenEndpoint endpoint = context.getBean("messageDrivenAdapter", JmsMessageDrivenEndpoint.class);
DefaultMessageListenerContainer container = TestUtils.getPropertyValue(endpoint, "listenerContainer",
DefaultMessageListenerContainer.class);
assertSame(context.getBean("exec"), TestUtils.getPropertyValue(container, "taskExecutor"));
endpoint.stop();
}
@Test
public void testGatewayWithReceiveTimeout() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<jms:message-driven-channel-adapter id="messageDrivenAdapter"
connection-factory="testConnectionFactory"
destination-name="testQueue"
task-executor="exec"
auto-startup="false"/>
<task:executor id="exec"/>
<bean id="testConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
<constructor-arg>
<bean class="org.springframework.integration.jms.StubConnection">
<constructor-arg value="message-driven-test"/>
</bean>
</constructor-arg>
</bean>
</beans>

View File

@@ -191,6 +191,16 @@
For more information see <xref linkend="chain"/>.
</para>
</section>
<section id="3.0-jms-mdca-te">
<title>JMS Message Driven Channel Adapter</title>
<para>
Previously, when configuring a <code>&lt;message-driven-channel-adapter/&gt;</code>, if you wished to
use a specific <interfacename>TaskExecutor</interfacename>, it was necessary to declare a container
bean and provide it to the adapter using the <code>container</code> attribute. The
<code>task-executor</code> is now provided, allowing it to be set directly on the adapter. This is
in addition to several other container attributes that were already available.
</para>
</section>
<section id="3.0-stored-proc-sql-return-type">
<title>SqlReturnType support for Stored Procedure components</title>
<para>