Delen via


Beperking simuleren in Microsoft 365-API's

Normaal gesproken is het testen van bandbreedtebeperking moeilijk omdat deze zelden optreedt, wanneer Microsoft 365-servers zwaar worden belast. Met behulp van de Dev Proxy kunt u throttling-responsen simuleren en nagaan of uw toepassing deze correct beheert.

Gebruik de GraphRandomErrorPlugin en de RetryAfterPlugin om throttling te simuleren op Microsoft 365-API's. De GraphRandomErrorPlugin retourneert throttelingreacties voor Microsoft 365-API’s. Hiermee RetryAfterPlugin wordt gecontroleerd of uw app wordt teruggezet volgens de instructies van de API.

Om te beginnen schakelt u in uw Dev Proxy-configuratiebestand het GraphRandomErrorPlugin en RetryAfterPlugin in.

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.24.0/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/*"
  ]
}

Let op

Voeg de RetryAfterPlugin toe vóór de GraphRandomErrorPlugin in uw configuratiebestand. Als u deze later toevoegt, wordt de aanvraag mislukt door de GraphRandomErrorPlugin voordat de RetryAfterPlugin aanvraag kan worden verwerkt.

Daarna configureer je de GraphRandomErrorPlugin om snelheidsbeperkingsfouten te simuleren.

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.24.0/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 ]
  }
}

Start Dev Proxy met uw configuratiebestand en test of uw app omgaat met throttling.

Als uw toepassing terugdeinst wanneer deze wordt beperkt door throttling, maar niet wacht op de tijd die is opgegeven voor de aanvragen, ziet u een bericht dat lijkt op Calling https://graph.microsoft.com/v1.0/endpoint again before waiting for the Retry-After period. Request will be throttled.

Dit bericht geeft aan dat uw toepassing de snelheidsbegrenzing niet correct afhandelt en onnodig verlenging veroorzaakt. Werk uw code bij om te wachten op de tijdsduur die is opgegeven in de Retry-After header voordat u de aanvraag opnieuw probeert uit te voeren om de manier waarop uw app het beperken afhandelt te verbeteren.