您目前查看的是 Apigee Edge 說明文件。
前往 Apigee X 說明文件。 info
本主題的學習內容
閱讀本主題後,您將瞭解:
- Apigee Edge 的要求和回應串流功能
- 要求和回應串流的使用時機
- 如何啟用要求和回應串流
什麼是要求和回應串流?
根據預設,HTTP 串流會停用,且 HTTP 要求和回應酬載會寫入記憶體中的緩衝區,然後再由 API Proxy 管道處理。如要變更這項行為,請啟用串流功能。啟用串流後,系統會將要求和回應的酬載串流至用戶端應用程式 (回應) 和目標端點 (要求),且不會進行修改。
何時該啟用串流功能?
如果 API Proxy 處理的要求和/或回應非常大 (如需大小限制,請參閱下方的「關於串流,還有哪些事項需要瞭解?」),建議啟用串流。
串流還有哪些注意事項?
即使啟用串流功能,Edge Cloud 和 Private Cloud 的訊息酬載大小仍限制為 10 MB。在非串流要求和回應中,如果超過該大小,就會導致 protocol.http.TooBigBody 錯誤。
在 Edge for Private Cloud 部署作業中,您可以修改非串流要求/回應大小限制。請務必先測試,再將變更部署至正式環境。
- 適用於 4.16.01 之前的 Edge for Private Cloud 版本:
在所有訊息處理器上,編輯http.properties檔案,增加HTTPResponse.body.buffer.limit參數的限制,然後重新啟動訊息處理器。 -
適用於 Edge for Private Cloud 4.16.01 以上版本:
-
編輯 /<inst_root>/apigee/customer/application/message-processor.properties 檔案。 如果該檔案不存在,請建立檔案。
-
在 message-processor.properties 中設定 conf_http_HTTPResponse.body.buffer.limit 屬性。例如:
conf_http_HTTPResponse.body.buffer.limit=5m -
重新啟動訊息處理器:
> /<inst_root>/apigee/apigee-service/bin/apigee-service edge-message-processor restart -
為所有訊息處理器重複執行上述步驟。
-
如何啟用要求和回應串流
如要啟用要求串流,您需要在 Proxy 套件的 ProxyEndpoint 和 TargetEndpoint 定義中新增 request.streaming.enabled 屬性,並將其設為 true。同樣地,設定 response.streaming.enabled 屬性即可啟用回應串流。
您可以在管理 UI 中,透過 Proxy 的「開發」檢視畫面找到這些設定檔。如果您是在本機開發,這些定義檔會位於 apiproxy/proxies 和 apiproxy/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 範例包括:
- streaming - Demonstrates an API proxy configured for HTTP streaming.
- Edge Callout:經簽署的網址產生器 - 說明產生經簽署的網址的最佳做法,以便存取大型檔案,而不是嘗試在要求/回應中串流播放檔案。