Microsoft 365 API'lerinde kısıtlama simülasyonu

Bir bakışta
Hedef: Uygulamanızın Microsoft 365 API sınırlamasını nasıl ele aldığını test etme
Süre: 10 dakika
Eklentiler:GraphRandomErrorPlugin, RetryAfterPlugin
Önkoşullar:Geliştirme Ara Sunucusunu Ayarlama

Genellikle, Microsoft 365 sunucuları ağır yük altında olduğunda nadiren gerçekleştiği için kısıtlama testi zordur. Geliştirme Proxy'sini kullanarak azaltma yanıtlarının benzetimini yapabilir ve uygulamanızın bunu doğru işleyip işlemediğini de kontrol edebilirsiniz.

Microsoft 365 API'lerinde azaltma simülasyonu yapmak için GraphRandomErrorPlugin ve RetryAfterPlugin kullanın. GraphRandomErrorPlugin Microsoft 365 API'leri için kısıtlama yanıtları döndürür. , RetryAfterPlugin uygulamanızın API tarafından açıklandığı gibi geri çekildiğini doğrular.

Başlamak için Dev Proxy yapılandırma dosyanızda GraphRandomErrorPlugin ve RetryAfterPlugin'i etkinleştirin.

Dosya:devproxyrc.json

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v3.1.0/rc.schema.json",
  "plugins": [
    {
      "name": "RetryAfterPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll"
    },
    {
      "name": "GraphRandomErrorPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/DevProxy.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/*"
  ]
}

Dikkat

Yapılandırma dosyanıza RetryAfterPluginGraphRandomErrorPlugin'in önüne ekleyin. Eğer bunu daha sonra eklerseniz, GraphRandomErrorPlugin işleme geçmeden önce RetryAfterPlugin tarafından istek başarısız olacaktır.

Kısıtlama hatalarının benzetimini yapmak için ardından GraphRandomErrorPlugin öğesini yapılandırın.

Dosya:devproxyrc.json (tam yapılandırma)

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v3.1.0/rc.schema.json",
  "plugins": [
    {
      "name": "RetryAfterPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll"
    },
    {
      "name": "GraphRandomErrorPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/DevProxy.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": {
    "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v3.1.0/graphrandomerrorplugin.schema.json",
    "allowedErrors": [ 429 ]
  }
}

Geliştirme Proxy'sini yapılandırma dosyanızla başlatın ve kısıtlamayı nasıl işlediğini görmek için uygulamanızı test edin.

Uygulamanız kısıtlandığında geri çekiliyorsa, ancak isteklerde belirtilen süreyi beklemiyorsa, Calling https://graph.microsoft.com/v1.0/endpoint again before waiting for the Retry-After period. Request will be throttled benzeri bir mesaj görürsünüz.

Bu mesaj, uygulamanızın kısıtlama yönetimini doğru şekilde yönetemediğini ve gereksiz yere kısıtlamayı uzattığını gösterir. Uygulamanızın kısıtlamayı işleme biçimini geliştirmek için, isteği yeniden denemeden önce Retry-After üst bilgi ile belirtilen süreyi bekleyecek şekilde kodunuzu güncelleyin.

Ayrıca bakınız