用于soap请求和回复的Spring集成网关中的超时问题

时间:2014-10-26 07:14:50

标签: spring-integration

我在从界面设置SOAP请求到ESB接口的超时时遇到了一些挑战(使用spring集成)。在将请求发送到ESB接口时,我设置请求超时= 5000毫秒并且回复超时= 5000毫秒但是如果服务在ESB接口上关闭,则请求在超过5000毫秒(5秒)的超时时间内超时并超时有时在40秒或更长时间。我尝试使用默认请求超时和默认回复超时选项以及int:gateway配置,但同样的问题。请参阅以下配置:

<int:gateway id="SoapESBGateway"
            service-interface="test.soap.service.ServiceSoap">
            <int:method name="ServiceResponse"
                request-channel="RequestChannel" reply-channel="ReplyChannel"
                request-timeout="5000" reply-timeout="5000" />
        </int:gateway>

        <int:chain input-channel="RequestChannel" output-channel="ReplyChannel">
        <int-xml:marshalling-transformer marshaller="marshaller" result-transformer="resultTransformer"></int-xml:marshalling-transformer>

        <int:transformer ref="TransformerBean" method="transformMethod"></int:transformer>

        <int-ws:outbound-gateway id="ws-SoapESB-gateway" ignore-empty-responses="true" uri="${soap.URI}"></int-ws:outbound-gateway>

        <int:transformer ref="TransformerBean" method="transformMethod"></int:transformer>

        <int-xml:unmarshalling-transformer unmarshaller="marshaller"></int-xml:unmarshalling-transformer>
        </int:chain>


        <bean id="resultTransformer" class="org.springframework.integration.xml.transformer.ResultToStringTransformer" />
        <bean id="TransformerBean" class="test.TransformerImpl"></bean>

如果我在设置超时选项时遗漏了某些内容,请告诉我。

谢谢, Vinay A


更新

<int:gateway id="SoapESBGateway"
                service-interface="test.soap.service.ServiceSoap">
                <int:method name="ServiceResponse"
                    request-channel="RequestChannel" reply-timeout="5000" />
            </int:gateway>

            <int:chain input-channel="RequestChannel">
            <int-xml:marshalling-transformer marshaller="marshaller" result-transformer="resultTransformer"></int-xml:marshalling-transformer>

            <int:transformer ref="TransformerBean" method="transformMethod"></int:transformer>

            <int-ws:outbound-gateway id="ws-SoapESB-gateway" ignore-empty-responses="true" uri="${soap.URI}" message-sender="messageSender"></int-ws:outbound-gateway>

            <int:transformer ref="TransformerBean" method="transformMethod"></int:transformer>

            <int-xml:unmarshalling-transformer unmarshaller="marshaller"></int-xml:unmarshalling-transformer>
            </int:chain>


            <bean id="resultTransformer" class="org.springframework.integration.xml.transformer.ResultToStringTransformer" />
            <bean id="TransformerBean" class="test.TransformerImpl"></bean>

<bean id ="messageSender" class="org.springframework.ws.transport.http.HttpComponentsMessageSender">
    <property name="connectionTimeout" value="2000"></property>
    </bean>

如上所述,我已经使用int-ws:outbound-gateway添加了messageSender bean引用,并设置了属性connectiontimeout = 2sec,但是我仍然可以看到,当网络关闭时,它会等待19秒进行首次命中接下来命中,不到19秒,但至少没有达到第一次命中所需的超时。所以,我们没有任何选择,我们可以确定所需的超时总是工作。

谢谢, 维奈

1 个答案:

答案 0 :(得分:1)

首先,请阅读本章:http://docs.spring.io/spring-integration/docs/latest-ga/reference/html/messaging-endpoints-chapter.html#d4e4197

根据您的配置,您有direct个流量,因此没有理由拥有request-timeoutreply-channel

40sec的问题属于WS网关的WebServiceMessageSender。在您的情况下,默认情况下为HttpUrlConnectionMessageSenderconnectTimeout中有一些HttpURLConnection属性。

我不确定如何更改它,但我更喜欢使用HttpComponentsMessageSender来更好地控制HTTP连接。

现在问题为Why is it 40sec, but not those 5sec from reply-timeout?。因为您的帖子在send上被屏蔽,但尚未到达wait reply部分。