INT-1848 Add order Attribute to tcp, udp, jdbc Outbound Endpoints

This commit is contained in:
Gary Russell
2011-03-25 15:49:00 -04:00
parent 6eb31e7e09
commit 16b0248791
8 changed files with 144 additions and 19 deletions

View File

@@ -100,6 +100,14 @@ task executors such as a WorkManagerTaskExecutor.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="order">
<xsd:annotation>
<xsd:documentation>
Specifies the order for invocation when this endpoint is connected as a
subscriber to a SubscribableChannel.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
@@ -176,6 +184,14 @@ inbound message was received.
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="order">
<xsd:annotation>
<xsd:documentation>
Specifies the order for invocation when this endpoint is connected as a
subscriber to a SubscribableChannel.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
@@ -268,6 +284,14 @@ A connection factory is needed by an outbound adapter. The connection factory mu
</xsd:attribute>
<xsd:attribute name="request-timeout" type="xsd:string"/>
<xsd:attribute name="reply-timeout" type="xsd:string"/>
<xsd:attribute name="order">
<xsd:annotation>
<xsd:documentation>
Specifies the order for invocation when this endpoint is connected as a
subscriber to a SubscribableChannel.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>

View File

@@ -73,7 +73,8 @@
so-send-buffer-size="53"
so-timeout="54"
local-address="127.0.0.1"
task-executor="externalTE"
task-executor="externalTE"
order="23"
/>
<ip:udp-outbound-channel-adapter id="testOutUdpiMulticast"
@@ -91,6 +92,7 @@
so-send-buffer-size="53"
so-timeout="54"
time-to-live="55"
order="12"
/>
<ip:tcp-connection-factory id="cfC1"
@@ -103,6 +105,7 @@
<ip:tcp-outbound-channel-adapter id="testOutTcpNio"
channel="tcpChannel"
connection-factory="cfC1"
order="35"
/>
<ip:tcp-connection-factory id="cfS2"
@@ -142,6 +145,7 @@
connection-factory="cfC2"
request-timeout="234"
reply-timeout="567"
order="24"
/>
<ip:tcp-connection-factory
@@ -238,11 +242,13 @@
<ip:tcp-outbound-channel-adapter id="tcpNewOut1"
channel="tcpChannel"
connection-factory="client1" />
connection-factory="client1"
order="25"/>
<ip:tcp-outbound-channel-adapter id="tcpNewOut2"
channel="tcpChannel"
connection-factory="server1" />
connection-factory="server1"
order="15"/>
<ip:tcp-inbound-channel-adapter id="tcpNewIn1"
channel="tcpChannel"

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 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.
@@ -24,6 +24,9 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -35,6 +38,8 @@ import org.springframework.core.serializer.Deserializer;
import org.springframework.core.serializer.Serializer;
import org.springframework.core.task.TaskExecutor;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.ip.tcp.TcpInboundGateway;
import org.springframework.integration.ip.tcp.TcpOutboundGateway;
import org.springframework.integration.ip.tcp.TcpReceivingChannelAdapter;
@@ -49,6 +54,7 @@ import org.springframework.integration.ip.udp.MulticastReceivingChannelAdapter;
import org.springframework.integration.ip.udp.MulticastSendingMessageHandler;
import org.springframework.integration.ip.udp.UnicastReceivingChannelAdapter;
import org.springframework.integration.ip.udp.UnicastSendingMessageHandler;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -104,19 +110,15 @@ public class ParserUnitTests {
TaskExecutor taskExecutor;
@Autowired
@Qualifier(value="client1")
AbstractConnectionFactory client1;
@Autowired
@Qualifier(value="client2")
AbstractConnectionFactory client2;
@Autowired
@Qualifier(value="cfC1")
AbstractConnectionFactory cfC1;
@Autowired
@Qualifier(value="cfC2")
AbstractConnectionFactory cfC2;
@Autowired
@@ -126,23 +128,18 @@ public class ParserUnitTests {
Deserializer<?> deserializer;
@Autowired
@Qualifier(value="server1")
AbstractConnectionFactory server1;
@Autowired
@Qualifier(value="server2")
AbstractConnectionFactory server2;
@Autowired
@Qualifier(value="cfS1")
AbstractConnectionFactory cfS1;
@Autowired
@Qualifier(value="cfS2")
AbstractConnectionFactory cfS2;
@Autowired
@Qualifier(value="cfS3")
AbstractConnectionFactory cfS3;
@Autowired
@@ -154,16 +151,19 @@ public class ParserUnitTests {
TcpSendingMessageHandler tcpNewOut2;
@Autowired
@Qualifier(value="tcpNewIn1")
TcpReceivingChannelAdapter tcpNewIn1;
@Autowired
@Qualifier(value="tcpNewIn2")
TcpReceivingChannelAdapter tcpNewIn2;
@Autowired
@Qualifier("errorChannel")
private MessageChannel errorChannel;
@Autowired
private DirectChannel udpChannel;
@Autowired
private DirectChannel tcpChannel;
@Test
public void testInUdp() {
@@ -231,6 +231,7 @@ public class ParserUnitTests {
assertEquals(54, dfa.getPropertyValue("soTimeout"));
assertEquals("127.0.0.1", dfa.getPropertyValue("localAddress"));
assertSame(taskExecutor, dfa.getPropertyValue("taskExecutor"));
assertEquals(23, dfa.getPropertyValue("order"));
assertEquals("testOutUdp",udpOut.getComponentName());
assertEquals("ip:udp-outbound-channel-adapter", udpOut.getComponentType());
}
@@ -253,6 +254,19 @@ public class ParserUnitTests {
assertEquals(53, dfa.getPropertyValue("soSendBufferSize"));
assertEquals(54, dfa.getPropertyValue("soTimeout"));
assertEquals(55, dfa.getPropertyValue("timeToLive"));
assertEquals(12, dfa.getPropertyValue("order"));
}
@Test
public void testUdpOrder() {
@SuppressWarnings("unchecked")
Set<MessageHandler> handlers = (Set<MessageHandler>) TestUtils
.getPropertyValue(
TestUtils.getPropertyValue(this.udpChannel, "dispatcher"),
"handlers");
Iterator<MessageHandler> iterator = handlers.iterator();
assertSame(this.udpOutMulticast, iterator.next());
assertSame(this.udpOut, iterator.next());
}
@Test
@@ -262,6 +276,7 @@ public class ParserUnitTests {
assertEquals("testOutTcpNio",tcpOut.getComponentName());
assertEquals("ip:tcp-outbound-channel-adapter", tcpOut.getComponentType());
assertFalse(cfC1.isLookupHost());
assertEquals(35, dfa.getPropertyValue("order"));
}
@Test
@@ -294,6 +309,7 @@ public class ParserUnitTests {
assertEquals("outGateway",tcpOutboundGateway.getComponentName());
assertEquals("ip:tcp-outbound-gateway", tcpOutboundGateway.getComponentType());
assertTrue(cfC2.isLookupHost());
assertEquals(24, dfa.getPropertyValue("order"));
}
@Test
@@ -380,12 +396,14 @@ public class ParserUnitTests {
public void testNewOut1() {
DirectFieldAccessor dfa = new DirectFieldAccessor(tcpNewOut1);
assertSame(client1, dfa.getPropertyValue("clientConnectionFactory"));
assertEquals(25, dfa.getPropertyValue("order"));
}
@Test
public void testNewOut2() {
DirectFieldAccessor dfa = new DirectFieldAccessor(tcpNewOut2);
assertSame(server1, dfa.getPropertyValue("serverConnectionFactory"));
assertEquals(15, dfa.getPropertyValue("order"));
}
@Test
@@ -401,4 +419,18 @@ public class ParserUnitTests {
assertSame(server1, dfa.getPropertyValue("serverConnectionFactory"));
}
@Test
public void testtCPOrder() {
@SuppressWarnings("unchecked")
Set<MessageHandler> handlers = (Set<MessageHandler>) TestUtils
.getPropertyValue(
TestUtils.getPropertyValue(this.tcpChannel, "dispatcher"),
"handlers");
Iterator<MessageHandler> iterator = handlers.iterator();
assertSame(this.tcpNewOut2, iterator.next()); //15
assertSame(this.tcpOutboundGateway, iterator.next()); //24
assertSame(this.tcpNewOut1, iterator.next()); //25
assertSame(this.tcpOut, iterator.next()); //35
}
}

View File

@@ -302,6 +302,14 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="order">
<xsd:annotation>
<xsd:documentation>
Specifies the order for invocation when this endpoint is connected as a
subscriber to a SubscribableChannel.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
@@ -425,6 +433,14 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="order">
<xsd:annotation>
<xsd:documentation>
Specifies the order for invocation when this endpoint is connected as a
subscriber to a SubscribableChannel.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

View File

@@ -1,3 +1,16 @@
/*
* Copyright 2002-2011 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. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.springframework.integration.jdbc.config;
import static junit.framework.Assert.assertTrue;
@@ -10,16 +23,25 @@ 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.jdbc.JdbcMessageHandler;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
/**
* @author Dave Syer
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gary Russell
* @since 2.0
*
*/
public class JdbcMessageHandlerParserTests {
private SimpleJdbcTemplate jdbcTemplate;
@@ -36,6 +58,8 @@ public class JdbcMessageHandlerParserTests {
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from FOOS");
assertEquals("Wrong id", "FOO", map.get("ID"));
assertEquals("Wrong id", "foo", map.get("name"));
JdbcMessageHandler handler = context.getBean(JdbcMessageHandler.class);
assertEquals(23, TestUtils.getPropertyValue(handler, "order"));
}
@Test

View File

@@ -1,3 +1,15 @@
/*
* Copyright 2002-2011 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. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.springframework.integration.jdbc.config;
import static junit.framework.Assert.assertTrue;
@@ -19,10 +31,19 @@ import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.jdbc.JdbcOutboundGateway;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
/**
* @author Dave Syer
* @author Oleg Zhurakousky
* @author Gary Russell
* @since 2.0
*
*/
public class JdbcOutboundGatewayParserTests {
private SimpleJdbcTemplate jdbcTemplate;
@@ -47,6 +68,8 @@ public class JdbcOutboundGatewayParserTests {
@SuppressWarnings("unchecked")
Map<String, ?> payload = (Map<String, ?>) reply.getPayload();
assertEquals("bar", payload.get("name"));
JdbcOutboundGateway gateway = context.getBean(JdbcOutboundGateway.class);
assertEquals(23, TestUtils.getPropertyValue(gateway, "order"));
}
@Test

View File

@@ -14,7 +14,7 @@
</si:channel>
<outbound-gateway id="jdbcGateway" query="select * from foos where id=:headers[id]" update="insert into foos (id, status, name) values (:headers[id], 0, :payload[foo])"
request-channel="target" reply-channel="output" data-source="dataSource" />
request-channel="target" reply-channel="output" data-source="dataSource" order="23"/>
<beans:import resource="jdbcOutboundChannelAdapterCommonConfig.xml" />

View File

@@ -10,7 +10,7 @@
http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd">
<outbound-channel-adapter query="insert into foos (id, status, name) values (:headers[business.key], 0, :payload)"
channel="target" jdbc-operations="jdbcTemplate" />
channel="target" jdbc-operations="jdbcTemplate" order="23"/>
<beans:import resource="jdbcOutboundChannelAdapterCommonConfig.xml" />