问题
How can I set default outgoing port and listening port for the reply on spring integration? Is it possible? I want to do that with tcp technology.
Here is my code:
<int-ip:tcp-connection-factory id="client"
type="client" host="${netSocketServer}" port="${netPort}"
single-use="true" so-timeout="${netSoTimeOut}" />
<int:channel id="input" />
<int-ip:tcp-outbound-gateway id="outGateway"
request-channel="input" reply-channel="reply" connection-factory="client"
request-timeout="${netRequestTimeout}" reply-timeout="${netReplyTimeout}" />
<int:channel id="reply" datatype="java.lang.String" />
Thanks in advance!
回答1:
Placeholders support defaults by including a :1234 part...
<int-ip:tcp-connection-factory id="client"
type="client" host="${netSocketServer}" port="${netPort:1234}"
single-use="true" so-timeout="${netSoTimeOut}" />
EDIT: per the comment below...
The framework doesn't support this out of the box at this time; you need to supply a custom TcpSocketFactorySupport to the connection factory (via the socket-factory-support attribute) to use the alternative connection strategies (allowing you to set the local port). If you need help, I might be able to post a gist in the next day or so.
I will shortly be starting work on a JIRA Issue that will make it easier to use some of these features.
Gist here. Bear in mind that setting the local port is unusual - usually the client side chooses an ephemeral port. The problem with hard-wiring the local port is it will fail to bind if it's in use (or is still in TIME_WAIT since it was last used).
来源:https://stackoverflow.com/questions/19815964/how-can-i-set-default-outgoing-port-and-listening-port-on-spring-integration