[JAVA] I examined the flow of TCP communication with Spring Integration (server edition)

Continuing from the last time, in order to organize the flow of TCP communication with Spring Integration, I drew a sequence diagram on the client side, although it is complicated.

Last time: I checked the flow of TCP communication with Spring Integration (client edition)

Spring IntegrationによるTCP接続のシーケンス

Pre-stage

It is assumed that ʻautoStartUp is enabled, that is, ʻInbound Gateway and ConnectionFactory are started when the application is started. That made the starting point strange: confounded :.

  1. ʻInbound Gateway calls the method that sets ConnectionFactory`.
  2. ConnectionFactory registers ʻInbound Gateway in Sender, Listener as a sender / receiver (ʻInbound Gateway implements TcpSender, TcpListener).
  3. Set the life cycle of ConnectionFactory to start.

TCP connection (preparation for reception from client)

  1. Ask ServerSocketFactory to generate ServerSocket based on the specified port number.
  2. Hold the received ServerSocket and make Socket wait for the connection to be accepted.
  3. Issue TcpConnectionServerListeningEvent.
  4. Build a TcpConnection based on the Socket.
  5. TcpConnection registers ʻInbound Gateway as a sender / receiver via ConnectionFactory`.
  6. ʻInbound Gateway holds TcpConnection`,
  7. Issue TcpConnectionOpenEvent.

TCP connection (reply to client)

  1. Receive a message from the client.
  2. Pass messages and channels to MessagingTemplate, which is a template for telegram conversion and business processing.
  3. Return the processing result to ʻInbound Gateway`.
  4. Pass the message to reply to TcpConnection.
  5. Pass the message to MessageMapper.
  6. MessageMapper extracts and returns the message payload.
  7. TcpConnection serializes the payload and returns it to the client.

Remarks: Although omitted in the figure, there are Channel and various endpoints between MessagingTemplate and ʻInbound Gateway`.

TCP connection (disconnect)

  1. Issue a ConnectionExceptionEvent if any exception occurs while the TCP connection is being established.
  2. Close Socket.
  3. TcpConnection asks ʻInbound Gateway` to remove the connection to disconnect from the list.
  4. Issue ConnectionCloseEvent.
  5. Ask the Processor, which manages the LifeCycle, to stop at the ʻInbound Gateway`.
  6. ʻInbound Gateway asks ConnectionFactory` to stop.
  7. ConnectionFactory closes ServerSocket.
  8. Close any TCP connections that still remain.
  9. TcpConnection asks ʻInbound Gateway` to remove the connection to disconnect from the list. Also, if there are any remaining tasks, delete them as well.

Remarks: I mentioned that when some exception occurred in 1, but it refers to the case where Socket is closed. For more information [TcpNetConneciton # run](https://github.com/spring-projects/spring-integration/blob/master/spring-integration-ip/src/main/java/org/springframework/integration/ip/ See tcp / connection / TcpNetConnection.java # L169).

The service used to create the diagram

The figure above was created using a service called WebSequenceDiagrams, continuing from the previous time.

Recommended Posts

I examined the flow of TCP communication with Spring Integration (server edition)
I examined the flow of TCP communication with Spring Integration (client edition)
How to access Socket directly with the TCP function of Spring Integration
Control the processing flow of Spring Batch with JavaConfig.
I want to understand the flow of Spring processing request parameters
I tried to build the environment of PlantUML Server with Docker
I tried to check the operation of gRPC server with grpcurl
How to check before sending a message to the server with Spring Integration
I checked the number of taxis with Ruby
Let's experience the authorization code grant flow with Spring Security OAuth-Part 1: Review of OAuth 2.0
I examined the life cycle of the extension of JUnit Jupiter
I tried using the Server Push function of Servlet 4.0
Access the built-in h2db of spring boot with jdbcTemplate
05. I tried to stub the source of Spring Boot
I tried to reduce the capacity of Spring Boot
Roughly the flow of web application development with Rails.
I made the server side of an online card game ①
A story packed with the basics of Spring Boot (solved)
I tried to take a look at the flow of Android development environment construction with Android Studio
I tried to solve the problem of "multi-stage selection" with Ruby
I tried the input / output type of Java Lambda ~ Map edition ~
I wanted to make JavaFX programming easier with the Spring Framework
See the behavior of entity update with Spring Boot + Spring Data JPA
I examined the concept of the process to understand how Docker works
I want to control the default error message of Spring Boot
Coexistence of Flyway in the embedded database (h2) of the development environment and the release database (SQL Server) with Spring Boot