Spring 集成 TCP - request/response 将请求切换到通道

Spring Integration TCP - request/response switch request to the channels

我正在做 Spring 与服务器和客户端的集成 request/response 演示。该请求带有一个字节数组,该数组将被转换为对象。然后请求进入输入通道,我需要检查将哪个 class 发送到服务激活器。然后服务激活器将其发送到回复通道。

<bean id="javaSerializer"
      class="org.springframework.core.serializer.DefaultSerializer"/>
      
<bean id="javaDeserializer"
      class="org.springframework.core.serializer.DefaultDeserializer"/> 

<!-- single-use="true" : A new message has to wait until the reply to the previous message has been received -->
<int-ip:tcp-connection-factory id="server"
    type="server"
    host="localhost"
    port="10101"
    single-use="true"
    so-timeout="10000"
    serializer="javaSerializer"
    deserializer="javaDeserializer" 
    task-executor="severTaskExecutor"/>
      
<int-ip:tcp-inbound-gateway id="inGateway"
    request-channel="inputChannel"
    reply-channel="replyChannel"
    connection-factory="server"
    reply-timeout="10000"/>
    
<int:channel id="inputChannel"/>

<!-- How to switch the request to the different channel??? -->

<int:channel id="myChannelOne"/>
<int:channel id="myChannelTwo"/>

<int:service-activator 
    input-channel="myChannelOne"
    output-channel="replyChannel"
    ref="myServiceOne"
    method="get" />
    
<int:service-activator 
    input-channel="myChannelTwo"
    output-channel="replyChannel"
    ref="myServiceTwo"
    method="get" />
    
<int:channel id="replyChannel"/>

<bean id="myServiceOne" class="com.my.demo.MyServiceOne"/>
<bean id="myServiceTwo" class="com.my.demo.MyServiceTwo"/>

使用负载类型路由器https://docs.spring.io/spring-integration/docs/current/reference/html/message-routing.html#router-implementations-payloadtyperouter

<int:payload-type-router input-channel="routingChannel">
    <int:mapping type="java.lang.String" channel="stringChannel" />
    <int:mapping type="java.lang.Integer" channel="integerChannel" />
</int:payload-type-router>