如何设置 Spring 集成回复的默认传出端口和监听端口? 是否可以? 我想用 TCP 技术来做到这一点。
这是我的代码:
<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" />
提前致谢!
最佳答案
占位符通过包含 :1234
部分来支持默认值...
<int-ip:tcp-connection-factory id="client"
type="client" host="${netSocketServer}" port="${netPort:1234}"
single-use="true" so-timeout="${netSoTimeOut}" />
编辑:根据下面的评论...
框架目前不支持开箱即用;您需要向连接工厂提供自定义的TcpSocketFactorySupport
(通过socket-factory-support
属性)以使用替代连接策略(允许您设置本地端口) 。如果您需要帮助,我也许可以在第二天左右发布要点。
我很快就会开始开发JIRA Issue这将使其中一些功能的使用变得更加容易。
Gist here 。请记住,设置本地端口并不常见 - 通常客户端会选择临时端口。硬连线本地端口的问题是,如果它正在使用中(或者自上次使用以来仍处于TIME_WAIT
状态),它将无法绑定(bind)。
关于java - 如何在Spring集成上设置默认的传出端口和监听端口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19815964/