2017-03-08 92 views
1

我正在使用Spring Integration進行REST調用,如下所示。持續連接/使用Spring Integration客戶端連接重用

<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握手。我如何重用連接併發出多個REST請求?有沒有可能使用保持活力?

更新-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> 

回答

0

考慮使用HttpComponentsClientHttpRequestFactory,而不是默認SimpleClientHttpRequestFactory。在Apache HTTP客戶端中,您可以找到足夠的連接管理選項,其中包括keep-alivehttps://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html

+0

請參見[此答案](http://stackoverflow.com/questions/35185025/default-keep-alive-time-for-a -httpconnection-when-using-spring-rest-template)獲取更多鏈接。 –

+0

謝謝,我添加了HttpComponentsClientHttpRequestFactory(更新了我上面的問題),但是我沒有看到有關如何在Spring集成環境中配置保持活動的屬性/示例 –

+0

已不是Spring集成責任。您必須從''添加'request-factory'引用。所有的事情都取決於'HttpComponentsClientHttpRequestFactory'配置。對我來說,我們給了你足夠的鏈接來閱讀這件事...... –