【问题标题】:Spring Integration TCP - request/response switch request to the channelsSpring Integration TCP - 对通道的请求/响应切换请求
【发布时间】:2021-11-20 05:52:26
【问题描述】:

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

<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"/>

【问题讨论】:

    标签: spring-integration


    【解决方案1】:

    使用负载类型路由器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>
    

    【讨论】:

    • 谢谢。它奏效了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-02
    • 1970-01-01
    • 1970-01-01
    • 2016-11-24
    • 2019-01-01
    • 2020-08-12
    • 1970-01-01
    相关资源
    最近更新 更多