简体   繁体   中英

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

My Spring Integration application built on TCP gateway is working well. 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.

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.

If yes, how should spring configuration be setup? I would appreciate any help in this regard.

Here is the spring context file:

<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> . One of the subscribers would be <int-jdbc:outbound-channel-adapter> to store reply to the DB. Another subscriber should be <bridge> without an output-channel assuming reply to the <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() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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