Sie können Richtlinien mit Ihrem bevorzugten Text- oder XML-fähigen Editor oder Ihrer IDE lokal erstellen und bearbeiten.
In diesem Thema wird der Kontingentrichtlinientyp als Beispiel für das Erstellen, Konfigurieren, Anhängen, Bereitstellen und Testen von Richtlinien verwendet.
Die meisten API-Proxys erzwingen ein Kontingent. Kontingente steuern, wie häufig eine Clientanwendung das Aufrufen einer API über ein bestimmtes Zeitintervall zulassen darf. Im folgenden Beispiel wird eine Kontingentrichtlinie konfiguriert, um Anwendungen auf eine Anfrage pro Minute zu beschränken. Auch wenn dies nicht realistisch ist, bietet es eine einfache Möglichkeit, die Auswirkungen einer Richtlinie zu sehen.
In einer API-Proxykonfiguration werden Richtliniendateien als XML-Dateien im Verzeichnis /apiproxy/policies gespeichert.
Beispielsweise könnte eine Richtlinie des Typs „Kontingentrichtlinie“ als Datei namens QuotaPolicy.xml mit folgendem Inhalt erstellt werden:
Sie können Textdateien manuell erstellen oder aus einem XML-Schema generieren. Alle Richtlinien haben Einstellungen, die für den jeweiligen Richtlinientyp spezifisch sind, und andere Einstellungen, die für alle Richtlinien gelten.
Wenn Sie in der Verwaltungsoberfläche Richtlinien hinzufügen, generiert der API-Proxy-Builder die Richtlinieninstanz aus dem XML-Schema für den ausgewählten Richtlinientyp. Daher sehen Sie in der Richtlinienkonfiguration möglicherweise Elemente, die nicht immer in der Dokumentation enthalten sind.
Alle Richtlinien definieren folgende Attribute:
enabled: Gibt an, ob die Richtlinie aktiviert oder deaktiviert ist. Über diese Einstellung können Richtlinien zur Laufzeit aktiviert/deaktiviert werden. Eine Richtlinie, bei der enabled auf false gesetzt ist, wird nicht erzwungen.
continueOnError: Definiert, ob die Pipeline die Nachricht weiter verarbeiten soll, wenn die Richtlinie fehlschlägt. Bei der Durchsetzung von Kontingentrichtlinien geben Fehler wahrscheinlich an, dass das Kontingent überschritten wurde. Dieses Attribut sollte daher auf „false“ gesetzt werden.
name: Der Name, den Sie der Richtlinie geben. Dieser Name ist für die Richtlinieninstanz einmalig und wird verwendet, um die Richtlinie als Verarbeitungsschritt an den Ablauf anzuhängen.
Im obigen Beispiel gelten die Elemente Allow, Interval und TimeUnit speziell für die Kontingentrichtlinie. Diese Elemente bieten Einstellungen, die API-Dienste für eine API erzwingen. Mit anderen Richtlinientypen werden eigene Einstellungen definiert, die Sie in der Richtlinienreferenz nachlesen können.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-04 (UTC)."],[[["\u003cp\u003eThis guide focuses on creating, configuring, attaching, deploying, and testing policies within Apigee and Apigee hybrid environments.\u003c/p\u003e\n"],["\u003cp\u003ePolicies, exemplified here by the Quota policy, are stored as XML files in the \u003ccode\u003e/apiproxy/policies\u003c/code\u003e directory within an API proxy configuration.\u003c/p\u003e\n"],["\u003cp\u003eThe Quota policy type allows control over API invocation frequency, as illustrated by an example that limits apps to one request per minute.\u003c/p\u003e\n"],["\u003cp\u003eAll policies, including the Quota policy, have attributes such as \u003ccode\u003eenabled\u003c/code\u003e, \u003ccode\u003econtinueOnError\u003c/code\u003e, and \u003ccode\u003ename\u003c/code\u003e, which define their behavior and status.\u003c/p\u003e\n"],["\u003cp\u003ePolicy-specific elements like \u003ccode\u003eAllow\u003c/code\u003e, \u003ccode\u003eInterval\u003c/code\u003e, and \u003ccode\u003eTimeUnit\u003c/code\u003e in the Quota policy example provide settings for enforcing API limits.\u003c/p\u003e\n"]]],[],null,["# Attaching and configuring policies in XML files\n\n*This page\napplies to **Apigee** and **Apigee hybrid**.*\n\n\n*View [Apigee Edge](https://docs.apigee.com/api-platform/get-started/what-apigee-edge) documentation.*\n\nYou can create and edit policies locally, using your favorite text or XML-aware editor or IDE.\nThis topic uses the Quota policy type as an example of how to create, configure, attach, deploy,\nand test policies.\n\nMost API proxies enforce a quota. Quotas provide control over how often a client app is\npermitted to invoke an API over a given time interval. In the example below, a Quota policy is\nconfigured to limit apps to 1 request per minute. (While this may not be realistic, it does\nprovide a simple way to see the effects of a policy.)\n\nIn an API proxy configuration, Policy files are stored as XML files under\n`/apiproxy/policies` directory.\n\nFor example, a policy of type Quota called Quota Policy could be created as a file called\n`QuotaPolicy.xml` with the following content: \n\n```text\n\u003cQuota enabled=\"true\" continueOnError=\"false\" name=\"QuotaPolicy\"\u003e\n \u003cAllow count=\"1\"/\u003e\n \u003cInterval\u003e1\u003c/Interval\u003e\n \u003cTimeUnit\u003eminute\u003c/TimeUnit\u003e\n\u003c/Quota\u003e\n```\n\nYou can create a text file by hand, or you can generate the policy from an XML schema. All\npolicies have some settings that are specific to the policy type, and some settings that are\ngeneric across all policies. \nWhen you attach policies in the management UI, the API proxy builder generates the policy instance from the XML schema for the policy type you selected. Therefore, you may see elements in the policy configuration that, for clarity, are not always included in documentation.\n\nAll policies define the following attributes:\n\n- `enabled`: Indicates whether the policy is turned *on* or *off* . Policies can be enabled/disabled at runtime by changing this setting. A policy that has `enabled` set to `false` is not enforced.\n- `continueOnError`: Defines whether the pipeline should continue processing the message if the policy fails. When enforcing quota policies, errors likely indicate that the quota has been exceeded, and, therefore, this attribute should be set to false.\n- `name`: The name that you give to this policy. This name is unique to this policy instance, and it is used to attach the policy to the flow as a processing step.\n\n| **Note:** Except for `name`, you rarely need to modify the default settings for these policy attributes. For this reason, and for clarity, they are often excluded from the policy samples in the documentation.\n\nIn the example above, the elements `Allow`, `Interval`, and\n`TimeUnit` are specific to the Quota policy. These elements provide settings that API\nServices enforces on behalf of an API. Other policy types define their own settings, which you\ncan learn about in the [Policy Reference](/apigee/docs/api-platform/reference/policies/reference-overview-policy)."]]