INT-1726 added poller support for JDBC outbound adapter/gateway

This commit is contained in:
Oleg Zhurakousky
2011-01-10 19:31:20 -05:00
parent 27c8d31889
commit fee03d435c
7 changed files with 132 additions and 13 deletions

View File

@@ -1,13 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[2.3.3.201005102200-CI-R3771-B739]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<enableImports><![CDATA[false]]></enableImports>
<configs>
</configs>
<configSets>
</configSets>
</beansProjectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[2.5.1.201011101000-RELEASE]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<enableImports><![CDATA[false]]></enableImports>
<configs>
<config>src/test/java/org/springframework/integration/jdbc/config/JdbcOutboundGatewayWithPollerTest-context.xml</config>
</configs>
<configSets>
</configSets>
</beansProjectDescription>

View File

@@ -252,6 +252,9 @@
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="queryType">
<xsd:sequence>
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="sql-parameter-source-factory" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
@@ -328,6 +331,7 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="update" type="xsd:string">
<xsd:annotation>

View File

@@ -9,11 +9,14 @@ import javax.sql.DataSource;
import org.junit.After;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
public class JdbcMessageHandlerParserTests {
@@ -73,6 +76,18 @@ public class JdbcMessageHandlerParserTests {
assertEquals("Wrong id", message.getHeaders().getId().toString(), map.get("ID"));
assertEquals("Wrong name", "bar", map.get("name"));
}
@Test
public void testOutboundAdapterWithPoller() throws Exception{
ApplicationContext ac = new ClassPathXmlApplicationContext("JdbcOutboundAdapterWithPollerTest-context.xml", this.getClass());
MessageChannel target = ac.getBean("target", MessageChannel.class);
Message<?> message = MessageBuilder.withPayload("foo").setHeader("business.key", "FOO").build();
target.send(message);
Thread.sleep(2000);
Map<String, Object> map = (ac.getBean("jdbcTemplate", JdbcTemplate.class)).queryForMap("SELECT * from FOOW");
assertEquals("Wrong id", "FOO", map.get("ID"));
assertEquals("Wrong id", "foo", map.get("name"));
}
@After
public void tearDown(){

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc-2.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
xmlns:jdbc="http://www.springframework.org/schema/jdbc">
<int:channel id="target">
<int:queue/>
</int:channel>
<int:channel id="output">
<int:queue />
</int:channel>
<int-jdbc:outbound-channel-adapter query="insert into foow (id, status, name) values (:headers[business.key], 0, :payload)"
channel="target" jdbc-operations="jdbcTemplate" >
<int:poller fixed-rate="1000"/>
</int-jdbc:outbound-channel-adapter>
<jdbc:embedded-database type="H2" id="dataSource">
<jdbc:script location="org/springframework/integration/jdbc/config/outboundPollerSchema.sql" />
</jdbc:embedded-database>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="dataSource" />
</bean>
</beans>

View File

@@ -10,6 +10,8 @@ import javax.sql.DataSource;
import org.junit.After;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
@@ -17,6 +19,7 @@ import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
public class JdbcOutboundGatewayParserTests {
@@ -72,6 +75,24 @@ public class JdbcOutboundGatewayParserTests {
assertEquals(1, payload.get("updated"));
}
@Test
public void testWithPoller() throws Exception{
ApplicationContext ac = new ClassPathXmlApplicationContext("JdbcOutboundGatewayWithPollerTest-context.xml", this.getClass());
Message<?> message = MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build();
MessageChannel target = ac.getBean("target", MessageChannel.class);
PollableChannel output = ac.getBean("output", PollableChannel.class);
target.send(message);
Thread.sleep(1000);
Map<String, Object> map = (ac.getBean("jdbcTemplate", JdbcTemplate.class)).queryForMap("SELECT * from BAZZ");
assertEquals("Wrong id", message.getHeaders().getId().toString(), map.get("ID"));
assertEquals("Wrong name", "bar", map.get("name"));
Message<?> reply = output.receive(1000);
assertNotNull(reply);
@SuppressWarnings("unchecked")
Map<String, ?> payload = (Map<String, ?>) reply.getPayload();
assertEquals("bar", payload.get("name"));
}
@After
public void tearDown() {
if (context != null) {

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc-2.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
xmlns:jdbc="http://www.springframework.org/schema/jdbc">
<int:channel id="target">
<int:queue/>
</int:channel>
<int:channel id="output">
<int:queue />
</int:channel>
<int-jdbc:outbound-gateway query="select * from bazz where id=:headers[id]" update="insert into bazz (id, status, name) values (:headers[id], 0, :payload[foo])"
request-channel="target" reply-channel="output" data-source="dataSource">
<int:poller fixed-rate="1000"/>
</int-jdbc:outbound-gateway>
<jdbc:embedded-database type="H2" id="dataSource">
<jdbc:script location="org/springframework/integration/jdbc/config/outboundPollerSchema.sql" />
</jdbc:embedded-database>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="dataSource" />
</bean>
</beans>

View File

@@ -0,0 +1,2 @@
create table bazz(id varchar(100),status int,name varchar(20));
create table foow(id varchar(100),status int,name varchar(20));