INT-3692: Example TCP Annotation Config

JIRA: https://jira.spring.io/browse/INT-3692

Polishing indents in the Docs.
This commit is contained in:
Gary Russell
2015-05-11 15:48:37 +01:00
committed by Artem Bilan
parent 093ab7924b
commit 5cbb2848a1

View File

@@ -1350,7 +1350,7 @@ The framework includes acknowledgment information in the data packet.
The framework includes acknowledgment information in the data packet.
| ip_tcp_remotePort
| REMOTE_PORT
| The remote port for a UDP packet.
| The remote port for a TCP connection.
| ip_connectionId
| CONNECTION_ID
| A unique identifier for a TCP connection; set by the framework for inbound messages; when sending to a server-side inbound channel adapter, or replying to an inbound gateway, this header is required so the endpoint can determine which connection to send the message to.
@@ -1358,3 +1358,101 @@ The framework includes acknowledgment information in the data packet.
| ACTUAL_CONNECTION_ID
| For information only - when using a cached or failover client connection factory, contains the actual underlying connection id.
|===
[[ip-annotation]]
=== Annotation-Based Configuration
The following example from the samples respository is used to illustrate some of the configuration options when using
annotations instead of XML.
[source, java]
----
@EnableIntegration <1>
@IntegrationComponentScan <2>
@Configuration
public static class Config {
@Value(${some.port})
private int port;
@MessagingGateway(defaultRequestChannel="toTcp") <3>
public interface Gateway {
String viaTcp(String in);
}
@Bean
@ServiceActivator(inputChannel="toTcp") <4>
public MessageHandler tcpOutGate(AbstractClientConnectionFactory connectionFactory) {
TcpOutboundGateway gate = new TcpOutboundGateway();
gate.setConnectionFactory(connectionFactory);
gate.setOutputChannelName("resultToString");
return gate;
}
@Bean <5>
public TcpInboundGateway tcpInGate(AbstractServerConnectionFactory connectionFactory) {
TcpInboundGateway inGate = new TcpInboundGateway();
inGate.setConnectionFactory(connectionFactory);
inGate.setRequestChannel(fromTcp());
return inGate;
}
@Bean
public MessageChannel fromTcp() {
return new DirectChannel();
}
@MessageEndpoint
public static class Echo { <6>
@Transformer(inputChannel="fromTcp", outputChannel="toEcho")
public String convert(byte[] bytes) {
return new String(bytes);
}
@ServiceActivator(inputChannel="toEcho")
public String upCase(String in) {
return in.toUpperCase();
}
@Transformer(inputChannel="resultToString")
public String convertResult(byte[] bytes) {
return new String(bytes);
}
}
@Bean
public AbstractClientConnectionFactory clientCF() { <7>
return new TcpNetClientConnectionFactory("localhost", this.port);
}
@Bean
public AbstractServerConnectionFactory serverCF() { <8>
return new TcpNetServerConnectionFactory(this.port);
}
}
----
<1> Standard Spring Integration annotation enabling the infrastructure for an integration application.
<2> Searches for `@MessagingGateway` interfaces.
<3> The entry point to the client-side of the flow. The calling application can `@Autowired` this `Gateway` bean
and invoke its method.
<4> Outbound endpoints consist of a `MessageHandler` and a consumer that wraps it. In this scenario, the
`@ServiceActivator` configures the endpoint according to the channel type.
<5> Inbound endpoints (in the TCP/UDP module) are all message-driven so just need to be declared as simple `@Bean` s.
<6> This class provides a number of POJO methods for use in this sample flow (a `@Transformer` and `@ServiceActivator`
on the server side, and a `@Transformer` on the client side).
<7> The client-side connection factory.
<8> The server-side connection factory.