简体   繁体   English

在TCP网关中发送响应后,向Spring Integration中的serviceActivator发送消息

[英]Sending message to serviceActivator in Spring Integration after sending response in TCP gateway

My Spring Integration application built on TCP gateway is working well. 我基于TCP网关构建的Spring Integration应用程序运行良好。 It takes request message coming to TCP gateway and forwards the message to serviceActivator for preparing the response and the response is sent to the client. 它接收到达TCP网关的请求消息,并将消息转发到serviceActivator以准备响应,然后将响应发送到客户端。

I would like to save the message to database after sending to the client. 我想在发送到客户端后将消息保存到数据库。 I am just wondering whether I can forward the message to another serviceActivator after sending the response to the client. 我只是想知道在将响应发送到客户端之后是否可以将消息转发到另一个serviceActivator。

If yes, how should spring configuration be setup? 如果是,应该如何设置弹簧配置? I would appreciate any help in this regard. 在这方面的任何帮助,我将不胜感激。

Here is the spring context file: 这是spring上下文文件:

<beans>
    <int-ip:tcp-connection-factory id="crLfServer"
            type="server"
            port="${availableServerSocket}"
            single-use="true"
            so-timeout="10000"
            using-nio="false" 
            serializer="connectionSerializeDeserialize"
            deserializer="connectionSerializeDeserialize"
            />

        <bean id="connectionSerializeDeserialize" class="org.springframework.integration.ip.tcp.serializer.ByteArrayStxEtxSerializer"/>

        <int-ip:tcp-inbound-gateway id="gatewayCrLf"
            connection-factory="crLfServer"
            request-channel="serverBytes2StringChannel"
            error-channel="errorChannel"
            reply-timeout="10000"/> <!-- reply-timeout works on inbound-gateway -->

        <int:channel id="toSA" />

        <int:service-activator input-channel="toSA"
            ref="myService"
            method="prepare"/>

        <int:object-to-string-transformer id="serverBytes2String"
            input-channel="serverBytes2StringChannel"
            output-channel="toSA"/>

        <int:transformer id="errorHandler"
            input-channel="errorChannel"
            expression="payload.failedMessage.payload + ':' + payload.cause.message"/>
</beans>

Thank you 谢谢

You can add <publish-subscribe-channel> as an output-channel for that <service-activator> . 您可以将<publish-subscribe-channel>添加为该<service-activator>output-channel One of the subscribers would be <int-jdbc:outbound-channel-adapter> to store reply to the DB. 订阅者之一将是<int-jdbc:outbound-channel-adapter>来存储对数据库的答复。 Another subscriber should be <bridge> without an output-channel assuming reply to the <int-ip:tcp-inbound-gateway >. 另一个订户应该是<bridge>而没有output-channel假定对<int-ip:tcp-inbound-gateway >的答复。

But yeah, it is before sending to client... 但是,是的,这是发送给客户之前 ...

For that purpose you can extend Serializer and perform desired logic with the byte[] already after performing super.serialize() . 为此,您可以在执行super.serialize()之后扩展Serializer并使用byte[]执行所需的逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM