I am configuring Spring integration setting. There are two TCP servers and it’s outbound-channel that shares same channel.
I want the channel to be routed using the header’s value. How can I solve this?
<ip:tcp-connection-factory id="admMsgRcvServer"
type="server" port="#{afiProperties.admMsgRcvPort}" deserializer="byteArrayCharLengthSerializer"
serializer="byteArrayCharLengthSerializer" single-use="true" />
<ip:tcp-connection-factory id="simMsgSndClient"
type="client" host="#{afiProperties.msgSndHost}" port="#{afiProperties.msgSndPort}"
single-use="true" so-timeout="10000" deserializer="byteArrayCharLengthSerializer"
serializer="byteArrayCharLengthSerializer" />
<ip:tcp-outbound-channel-adapter id="msgSnd"
connection-factory="simMsgRcvServer" channel="afiHeadToHeaderChannel" />
<ip:tcp-outbound-channel-adapter id="simMsgSnd"
channel="afiHeadToHeaderChannel" connection-factory="simMsgSndClient" />
You can use an to route to a channel based on the value of a header.
That said, one of your adapters uses a “server” connection factory; that won’t work as configured. You can’t send arbitrary messages to a connection created by a server connection factory; it usually has to be a reply to an incoming message; there are some advanced techniques to do it, but you always need at least one incoming message first.