0

我有 SOAP 服务,它使用 tcp 连接与外部服务进行交互。我为此 tcp 服务使用连接池。当我启动我的应用程序并发送第一个 SOAP 请求时 - 一切正常,但如果我等待 1 分钟 - 那么我没有得到响应。但是当我用 Wireshark 嗅探流量时——我明白了,返回的是什么响应。还有一点点额外的 - 如果我没有等待 1 分钟并发送新请求 - 一切正常。仅当等待 1 分钟时才会出现问题。这是我对池和 tcp 的配置:

<beans profile="single">
    <bean id="testConnectionFactory" class="com.test.provider.impl.ProviderTcpConnectionFactory">
        <constructor-arg name="host" value="localhost"/>
        <constructor-arg name="port" value="7700"/>
        <property name="connectionTimeout" value="10000"/>
        <property name="soTimeout" value="60000"/>
        <property name="deserializer" ref="testDeserializer"/>
        <property name="singleUse" value="true"/>
    </bean>
</beans>

<beans profile="pool">
    <bean id="testConnection" class="com.test.provider.impl.ProviderTcpConnectionFactory">
        <constructor-arg name="host" value="localhost"/>
        <constructor-arg name="port" value="7700"/>
        <property name="connectionTimeout" value="10000"/>
        <property name="soTimeout" value="60000"/>
        <property name="deserializer" ref="testDeserializer"/>
        <property name="singleUse" value="true"/>
    </bean>
    <bean id="testConnectionFactory" class="org.springframework.integration.ip.tcp.connection.CachingClientConnectionFactory">
        <constructor-arg ref="testConnection"/>
        <constructor-arg value="5"/>
    </bean>
</beans>

在日志中我看到下一行

DEBUG [org.springframework.integration.ip.tcp.connection.TcpNetConnection] Closed single use socket after timeout

据我了解 - soTimeout 过期后套接字关闭。但是如何在不关闭连接的情况下使用池?

4

1 回答 1

1

这是CachingClientConnectioNFactory; 它不能正确处理以这种方式超时的连接;连接实际上并未关闭,读取器线程已终止。

请打开一个JIRA 问题;谢谢。

解决方法可能是删除 soTimeout 属性;您还可以在服务器端放置一个 soTimeout,以便它启动关闭。

实际上,鉴于您正在使用single-use="true"(每个连接都有一个新套接字),您不会从使用CachingClientConnectionFactory;中获得任何好处。它旨在提供一个共享连接池。

于 2013-09-21T19:14:09.150 回答