模擬 Microsoft 365 API 上的節流
一般而言,當 Microsoft 365 伺服器負載過重時,測試 節流 很困難,因為它很少發生。 您可以使用 Dev Proxy 來模擬節流回應,並檢查您的應用程式是否正確處理。
若要模擬 Microsoft 365 API 上的節流,請使用 GraphRandomErrorPlugin 和 RetryAfterPlugin。 會 GraphRandomErrorPlugin
傳回 Microsoft 365 API 的節流回應。 會 RetryAfterPlugin
依照 API 指示,驗證您的應用程式是否關閉。
若要開始,請在您的 Dev Proxy 組態檔中開啟 GraphRandomErrorPlugin
和 RetryAfterPlugin
。
{
"$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.14.1/rc.schema.json",
"plugins": [
{
"name": "RetryAfterPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll"
},
{
"name": "GraphRandomErrorPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
"configSection": "graphRandomErrorPlugin"
}
],
"urlsToWatch": [
"https://graph.microsoft.com/v1.0/*",
"https://graph.microsoft.com/beta/*",
"https://graph.microsoft.us/v1.0/*",
"https://graph.microsoft.us/beta/*",
"https://dod-graph.microsoft.us/v1.0/*",
"https://dod-graph.microsoft.us/beta/*",
"https://microsoftgraph.chinacloudapi.cn/v1.0/*",
"https://microsoftgraph.chinacloudapi.cn/beta/*",
"!https://*.sharepoint.*/*_api/web/GetClientSideComponents",
"https://*.sharepoint.*/*_api/*",
"https://*.sharepoint.*/*_vti_bin/*",
"https://*.sharepoint-df.*/*_api/*",
"https://*.sharepoint-df.*/*_vti_bin/*"
]
}
警告
在組態檔中新增 RetryAfterPlugin
之前 GraphRandomErrorPlugin
。 如果您在之後新增它,則要求會在有機會處理之前RetryAfterPlugin
失敗GraphRandomErrorPlugin
。
接下來,設定 GraphRandomErrorPlugin
以模擬節流錯誤。
{
"$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.14.1/rc.schema.json",
"plugins": [
{
"name": "RetryAfterPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll"
},
{
"name": "GraphRandomErrorPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
"configSection": "graphRandomErrorPlugin"
}
],
"urlsToWatch": [
"https://graph.microsoft.com/v1.0/*",
"https://graph.microsoft.com/beta/*",
"https://graph.microsoft.us/v1.0/*",
"https://graph.microsoft.us/beta/*",
"https://dod-graph.microsoft.us/v1.0/*",
"https://dod-graph.microsoft.us/beta/*",
"https://microsoftgraph.chinacloudapi.cn/v1.0/*",
"https://microsoftgraph.chinacloudapi.cn/beta/*",
"!https://*.sharepoint.*/*_api/web/GetClientSideComponents",
"https://*.sharepoint.*/*_api/*",
"https://*.sharepoint.*/*_vti_bin/*",
"https://*.sharepoint-df.*/*_api/*",
"https://*.sharepoint-df.*/*_vti_bin/*"
],
"graphRandomErrorPlugin": {
"allowedErrors": [ 429 ]
}
}
使用組態檔啟動 Dev Proxy 並測試您的應用程式,以瞭解其如何處理節流。
如果您的應用程式在節流時回復,但不會等候要求上指定的時間量,您會看到類似 Calling https://graph.microsoft.com/v1.0/endpoint again before waiting for the Retry-After period. Request will be throttled
的訊息。
此訊息表示您的應用程式未正確處理節流,而且不必要地延長節流。 若要改善應用程式處理節流的方式,請先更新程式代碼以等候標頭中指定的 Retry-After
時間量,然後再重試要求。