how to implement a TCP connection pool in Spring Integration

那年仲夏 提交于 2019-12-12 01:52:32

问题


I would like to be able to implement a TCP connection pool/factory that will be able to accept a dynamic host during runtime.

For example I have an outbound channel adapter that is referenced to a client connection factory. The host will need to change depending on the message in the outbound channel adapter.

I know that the host is static in this configuration. My question is, how to customize or extend the class for tcp-connection-factory to be able to connect to changing hosts. Or if there's other better way to fulfill the expected outcome, what would be that solution?

<int-ip:tcp-outbound-channel-adapter
    id="outAdapter" 
    channel="outChannel"
    connection-factory="client" />

<int-ip:tcp-connection-factory id="client"
    type="client"
    host="${dynamicHost}"
    port="1234"
    single-use="false"
    so-timeout="10000" />

回答1:


It's not currently possible/easy - we have an open new feature request in JIRA to provide that functionality.

The problem is that the connection factory does not currently have access to the message when the adapter calls its getConnection() method. So we need some API changes to properly support this feature.

In the meantime, you could write your own delegating connection factory but it would not be trivial and you would need to use a ThreadLocal or similar to communicate the message context to the factory so it can decide which connection is needed.



来源:https://stackoverflow.com/questions/29768046/how-to-implement-a-tcp-connection-pool-in-spring-integration

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