使用Spring Integration Client使用持续的连接 /连接重复使用



我使用以下弹簧集成进行休息呼叫。

<int:gateway id="ServiceRequestGateway"
                 service-interface="com.company.security.integration.RequestGateway"
                 default-request-channel="RequestChannel"
                 default-reply-channel="ResponseChannel">
        <int:default-header name="Accept" value="application/json; v=5"/>
        <int:default-header name="Content-Type" value="application/json; v=5"/>
        <int:default-header name="ServiceType" expression="#args[1]"/>
    </int:gateway>
    <int-http:outbound-gateway
            id="Outbound_Gateway"
            request-channel="RequestChannel"
            reply-channel="ResponseChannel"
            header-mapper="headerMapper"
            url="${service.host}/{xyzServiceType}"
            http-method="POST"
            expected-response-type="java.lang.String"
            extract-request-payload="true">
        <int-http:uri-variable name="ServiceType" expression="headers['xyzServiceType']" />
    </int-http:outbound-gateway>

但是,网络上的每个呼叫都会发生很多SSL握手。如何重复使用连接并提出多个休息请求?是否可以使用饲养场?

update-1

添加了httpcomponentsclienthttprequestfactory的使用。

<int-http:outbound-gateway
        id="NPI_Tokenization_Outbound_Gateway"
        request-channel="NPITokenizationRequestChannel"
        reply-channel="ResponseChannel"
        header-mapper="headerMapper"
        url="${npi.turing.host}/{npiTuringType}"
        http-method="POST"
        expected-response-type="java.lang.String"
        extract-request-payload="true">
    <int-http:uri-variable name="npiTuringType" expression="headers['npiTuringType']" />
</int-http:outbound-gateway>
<bean id="requestFactory"
      class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory">
    <property name="connectTimeout" value="5000"/>
    <property name="readTimeout"    value="5000"/>
</bean>

考虑使用HttpComponentsClientHttpRequestFactory而不是默认的SimpleClientHttpRequestFactory。在Apache HTTP客户端中,您可以找到足够的连接管理选项,包括keep-alive:https://hc.apache.org/httpcomponents-client-ga/tutorial/html/html/connmgmt.htmgmt.html

最新更新