spring integration学习入门之tcp通讯

第一次编写csdn的博客,只怪stackoverflow死活登不上,没办法了

最近工作需要需要使用springintegration,以前没有使用过,不得已从头开始学习,资料也甚是不全,只能自己到处找英文原版看,也是辛苦,弄了好几天,总算跑通了helloworld和tcp的通讯了。

闲言少叙,直接上干货。

 

环境搭建

Maven 获取项目所需源代码

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bocom.bbip</groupId>
<artifactId>bbip-integration-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<spring.version>3.2.1.RELEASE</spring.version>
<spring.integration.version>4.1.8.RELEASE</spring.integration.version>
<java.version>1.6</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>




<dependencies>
<!-- Spring Integration -->
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>${spring.integration.version}</version>
</dependency>


<!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-ip</artifactId>
<version>${spring.integration.version}</version>
</dependency>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
以下是一个Spring Integration实现接入TCP的示例: ```java @Configuration @EnableIntegration public class TcpIntegrationConfig { @Bean public AbstractServerConnectionFactory tcpServerConnectionFactory() { TcpNetServerConnectionFactory factory = new TcpNetServerConnectionFactory(9876); factory.setDeserializer(new ByteArrayRawDeserializer()); factory.setSerializer(new ByteArrayRawSerializer()); return factory; } @Bean public MessageChannel tcpInputChannel() { return new DirectChannel(); } @Bean public TcpReceivingChannelAdapter tcpReceivingChannelAdapter() { TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter(); adapter.setConnectionFactory(tcpServerConnectionFactory()); adapter.setOutputChannel(tcpInputChannel()); return adapter; } @ServiceActivator(inputChannel = "tcpInputChannel") public void handleTcpMessage(byte[] message) { // process the message here } } ``` 在上面的示例中,我们定义了一个TCP服务器连接工厂,并将其绑定到默认端口9876。我们还定义了一个输入通道(tcpInputChannel),以便接收TCP请求的消息。然后,我们将TCP接收通道适配器(TcpReceivingChannelAdapter)绑定到TCP服务器连接工厂,并将其输出通道设置为输入通道。最后,我们将服务激活器(ServiceActivator)绑定到输入通道,以便在接收到TCP请求时处理请求的内容。 注意:在实际使用时,需要根据具体的情况进行修改。特别是TCP端口和处理TCP请求的方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值