如何在 spring 集成中设置默认传出端口和侦听端口? [英] How can I set default outgoing port and listening port on spring integration?

查看:24
本文介绍了如何在 spring 集成中设置默认传出端口和侦听端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为spring集成的回复设置默认的传出端口和监听端口?有可能吗?我想用 tcp 技术做到这一点.

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.

这是我的代码:

<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" /> 

提前致谢!

推荐答案

Placeholders 通过包含 :1234 部分支持默认值...

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}" />

根据下面的评论...

框架目前不支持开箱即用;您需要向连接工厂提供自定义 TcpSocketFactorySupport(通过 socket-factory-support 属性)以使用替代连接策略(允许您设置本地端口).如果你需要帮助,我可能会在第二天左右发布一个要点.

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.

我将很快开始处理 JIRA 问题,这将使您更容易使用其中一些功能.

I will shortly be starting work on a JIRA Issue that will make it easier to use some of these features.

要点在这里.请记住,设置本地端口是不寻常的——通常客户端会选择一个临时端口.硬连线本地端口的问题是,如果它正在使用中(或自上次使用以来仍处于 TIME_WAIT 中),它将无法绑定.

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).

这篇关于如何在 spring 集成中设置默认传出端口和侦听端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆