Skip to content

About

使用Spring Boot以及Spring Integration构建的Socket通信客户端演示项目(使用Java配置)

Resources

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Socket Client with Spring Boot and Spring Integration using Java Config Demo Project

使用Spring Boot以及Spring Integration构建的Socket通信客户端演示项目(使用Java配置)

使用方法

  1. mvn spring-boot:run
  2. curl -X POST -H 'Content-Type: text/plain' -d "消息内容" http://localhost:8080

说明

  • 注意在DemoApplication上增加了@IntegrationComponentScan注解才能正确扫描到@MessagingGateway,使用方法与@ComponentScan相同。
  • TCP通信使用到了org.springframework.integration:spring-integration-ip包,需要在pom.xml中增加。
  • com.dewafer.demo.server包下的内容为演示使用的远程Socket仿真服务器,该服务器在程序启动时会一起启动。
  • 配置文件主要参考com.dewafer.demo.config.IntegrationConfig。
  • TcpClientGateway使用方法的演示在DemoController中。
  • 整个Integration flow大致为 http POST request --> DemoController --> TcpClientGateway --> requestChannel --> tcpOutboundGateway --> tcpInboundChannel --> objectToStringTransformer --> replyChannel --> TcpClientGateway --> DemoController --> http response
  • 因为flow比较简单没有使用DSL进行配置。
  • 所有的Channel皆为DirectChannel,整个flow在一个thread上完成。
  • 因为演示用的Socket仿真服务器使用了java.io.DataInputStream#readUTF方法,所以为TcpOutboundGateway配置了HEADER_SIZE_UNSIGNED_SHORT的ByteArrayLengthHeaderSerializer,请根据实际情况替换Serializer。请参考相关的官方文档。

About

使用Spring Boot以及Spring Integration构建的Socket通信客户端演示项目(使用Java配置)

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages