Spring Integration. Unknown host and tcp-connection-factory

假装没事ソ 提交于 2019-12-23 04:52:08

问题


I'm implementing the TCP client using the Spring Integration. The requirements are: 1. Through the UDP connection (from somewhere) receive the ip or host address of the TCP server. 2. Open TCP connection to the server, to the destination host from previous step and send some business data to this server.

I use the Spring Integration framework, version "2.2.0.RELEASE", and the problem is that in the default configuration of the tcp-connection-factory the host attribute should be "hardcoded" in xml. For example:

<ip:tcp-connection-factory id="client" type="client" host="localhost" port="1234" single-use="true"/>

The question is how to avoid the static definition of the destination host in application context, and be able to 'lazy' initialise the tcp-connection-factory when the destination host will be known.

I know that this flow could be easily implemented by the standard Network APIs of Java, and the question is specific about the Spring-Integration API


回答1:


At this time, the configuration is static.

You could however use a similar technique to that used in the dynamic ftp sample which configures ftp outbound adapters at runtime.




回答2:


As far as <int-ip:tcp-connection-factory> provides some instance of AbstractConnectionFactory. And from other side <int-ip:tcp-outbound-channel-adapter> applies that instance via connection-factory, so, there is no stops to implement your own RoutingConnectionFactory.

The implementation may rely on some value from ThreadLocal. The idea is here:

https://github.com/spring-projects/spring-amqp/blob/master/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/AbstractRoutingConnectionFactory.java,

https://github.com/spring-projects/spring-framework/blob/master/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java




回答3:


It's not currently possible/easy - even if you customize or extend the class for tcp-connection-factory to be able to connect to changing hosts. There is an open new feature request in JIRA to provide this functionality.



来源:https://stackoverflow.com/questions/21432929/spring-integration-unknown-host-and-tcp-connection-factory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!