Using the Java DSL for TCP Components
TCP 组件的 DSL 支持包括适配器和网关规范、带有创建连接工厂 bean 的工厂方法的 Tcp
类,以及带有创建序列化器和反序列化器的工厂方法的 TcpCodecs
类。有关更多信息,请参阅它们的 Java 文档。
DSL support for TCP components includes specs for adapters and gateways, the Tcp
class with factory methods to create connection factory beans, and the TcpCodecs
class with factory methods to create serializers and deserializers.
Refer to their javadocs for more information.
下面是一些使用 DSL 来配置使用 DSL 的流的示例。
Here are some examples of using the DSL to configure flows using the DSL.
Server Adapter Flow
@Bean
public IntegrationFlow server() {
return IntegrationFlow.from(Tcp.inboundAdapter(Tcp.netServer(1234)
.deserializer(TcpCodecs.lengthHeader1())
.backlog(30))
.errorChannel("tcpIn.errorChannel")
.id("tcpIn"))
.transform(Transformers.objectToString())
.channel("tcpInbound")
.get();
}
Client Adapter Flow
@Bean
public IntegrationFlow client() {
return f -> f.handle(Tcp.outboundAdapter(Tcp.nioClient("localhost", 1234)
.serializer(TcpCodecs.lengthHeader1())));
}
Server Gateway Flow
@Bean
public IntegrationFlow server() {
return IntegrationFlow.from(Tcp.inboundGateway(Tcp.netServer(1234)
.deserializer(TcpCodecs.lengthHeader1())
.serializer(TcpCodecs.lengthHeader1())
.backlog(30))
.errorChannel("tcpIn.errorChannel")
.id("tcpIn"))
.transform(Transformers.objectToString())
.channel("tcpInbound")
.get();
}
Client Gateway Flow
@Bean
public IntegrationFlow client() {
return f -> f.handle(Tcp.outboundGateway(Tcp.nioClient("localhost", 1234)
.deserializer(TcpCodecs.lengthHeader1())
.serializer(TcpCodecs.lengthHeader1())));
}