串流要求和回應

您正在查看 Apigee Edge 說明文件。
查看 Apigee X 說明文件
資訊

本主題課程內容

閱讀這個主題後,您將瞭解:

  • Apigee Edge 上的要求與回應串流是什麼
  • 使用要求和回應串流的時機
  • 如何啟用要求和回應串流

什麼是要求和回應串流?

根據預設,系統會停用 HTTP 串流,並先將 HTTP 要求和回應酬載寫入記憶體中的緩衝區,再由 API Proxy 管道處理。您可以啟用串流功能來變更這項行為。啟用串流功能後,系統會串流要求和回應酬載,而不會修改用戶端應用程式 (用於回應) 和目標端點 (針對要求)。

何時該啟用串流功能?

如果您的 API Proxy 處理非常大量的要求和/或回應 (如要瞭解大小限制,請參閱下方的「串流相關注意事項」一節),建議您啟用串流功能。

針對串流功能,我還需要瞭解哪些資訊?

即使已啟用串流功能,訊息酬載大小仍限制為 10 MB,邊緣雲端和私有雲。在非串流要求和回應中,如果超過該大小,就會產生 protocol.http.TooBigBody 錯誤。

在 Edge 私人雲端部署項目中,您可以修改非串流要求/回應大小限制。將變更部署至實際工作環境前,請務必先進行測試。

  • 針對 Edge for Private Cloud 4.16.01 之前的版本:

    請編輯所有訊息處理器的 http.properties 檔案,提高 HTTPResponse.body.buffer.limit 參數中的限制,然後重新啟動訊息處理器。
  • 如為 Edge for Private Cloud 4.16.01 以上版本:
    1. 編輯檔案 /<inst_root>/apigee/customer/application/message-processor.properties。 如果該檔案不存在,請建立一個。

    2. message-processor.properties 中設定 conf_http_HTTPResponse.body.buffer.limit 屬性。例如:
      conf_http_HTTPResponse.body.buffer.limit=5m

    3. 重新啟動訊息處理器:
      > /<inst_root>/apigee/apigee-service/bin/apigee-service Edge-message-processor 重新啟動

    4. 對所有訊息處理器重複以上步驟。

如何啟用要求和回應串流

如要啟用要求串流功能,您必須將 request.streaming.enabled 屬性新增至 Proxy 組合中的 ProxyEndpoint 和 TargetEndpoint 定義,並將其設為 true。同樣地,請設定 response.streaming.enabled 屬性,啟用回應串流。

您可以在 Proxy 的「開發」檢視畫面的管理 UI 中找到這些設定檔。如果您是在本機進行開發,這些定義檔案就位於 apiproxy/proxiesapiproxy/targets

這個範例說明如何在 TargetEndpoint 定義中啟用要求和回應串流。

<TargetEndpoint name="default">
  <HTTPTargetConnection>
    <URL>http://mocktarget.apigee.net</URL>
    <Properties>
      <Property name="response.streaming.enabled">true</Property>
      <Property name="request.streaming.enabled">true</Property>
      <Property name="supports.http10">true</Property>
      <Property name="request.retain.headers">User-Agent,Referer,Accept-Language</Property>
      <Property name="retain.queryparams">apikey</Property>
    </Properties>
  </HTTPTargetConnection>
</TargetEndpoint>

以下範例說明如何在 ProxyEndpoint 定義中啟用回應和要求串流:

<ProxyEndpoint name="default">
  <HTTPProxyConnection>
    <BasePath>/v1/weather</BasePath>
    <Properties>
      <Property name="allow.http10">true</Property>
      <Property name="response.streaming.enabled">true</Property>
      <Property name="request.streaming.enabled">true</Property>
    </Properties>
  </HTTPProxyConnection>
</ProxyEndpoint>

如要進一步瞭解如何設定端點定義,請參閱端點屬性參考資料

相關程式碼範例

GitHub 上的 API Proxy 範例非常容易下載及使用。如需下載和使用範例的相關資訊,請參閱「使用範例 API Proxy」。

功能串流的 Proxy 範例包括: