Anti-Pattern: Auf Anfrage-/Antwort-Nutzlast zugreifen, wenn Streaming aktiviert ist
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Sie lesen gerade die Dokumentation zu Apigee und Apigee Hybrid. Apigee Edge-Dokumentation aufrufen.
Das Standardverhalten in Apigee ist, dass HTTP-Anfrage- und -Antwort-Nutzlasten in einem speicherinternen Zwischenspeicher gespeichert werden, bevor sie von den Richtlinien im API-Proxy verarbeitet werden.
Wenn das Streaming aktiviert ist, werden die Nutzlasten von Anfragen und Antworten ohne Änderung an der Clientanwendung (für Antworten) und dem Zielendpunkt (für Anfragen) gestreamt. Das Streaming ist insbesondere dann hilfreich, wenn eine Anwendung große Nutzlasten akzeptiert oder zurückgibt oder wenn eine Anwendung Daten zurückgibt, die in Zeitblöcken zurückgegeben werden.
Anti-Pattern
Der Zugriff auf die Anfrage-/Antwort-Nutzlast mit aktiviertem Streaming veranlasst Apigee, in den Standardpuffermodus zurückzukehren.
Abbildung 1: Auf Anfrage-/Antwort-Nutzlast mit aktiviertem Streaming zugreifen
Die Abbildung oben zeigt, dass wir versuchen, Variablen aus der Nutzlast der Anfrage zu extrahieren und die Nutzlast der JSON-Antwort mithilfe der JSONToXML-Richtlinie in XML umzuwandeln. Dadurch wird das Streaming in Apigee deaktiviert.
Auswirkungen
Das Streaming wird deaktiviert, was zu höheren Latenzen bei der Datenverarbeitung führen kann.
Die Steigerung der Heap-Speichernutzung oder der OutOfMemory-Fehler kann aufgrund der Verwendung von In-Memory-Zwischenspeichern beobachtet werden, insbesondere wenn große Anfrage-/Antwort-Nutzlasten vorliegen.
Best Practice
Greifen Sie nicht auf die Anfrage-/Antwort-Nutzlast zu, wenn das Streaming aktiviert ist.
[[["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\u003eApigee's default behavior involves buffering HTTP request and response payloads in memory, but streaming can be enabled to send payloads directly to clients or target endpoints.\u003c/p\u003e\n"],["\u003cp\u003eAccessing request or response payloads when streaming is enabled in Apigee will revert the system to the default buffering mode.\u003c/p\u003e\n"],["\u003cp\u003eDisabling streaming by accessing the request/response payload can result in increased latency and higher memory consumption, potentially leading to \u003ccode\u003eOutOfMemory\u003c/code\u003e errors.\u003c/p\u003e\n"],["\u003cp\u003eThe recommended practice is to avoid accessing the request/response payload when streaming is active to maintain the benefits of streaming.\u003c/p\u003e\n"],["\u003cp\u003eStreaming is beneficial for applications that handle large payloads or data delivered in chunks over time.\u003c/p\u003e\n"]]],[],null,["# Antipattern: Accessing the request/response payload when streaming is enabled\n\n*You're viewing **Apigee** and **Apigee hybrid** documentation.\nView [Apigee Edge](https://docs.apigee.com/api-platform/antipatterns/payload-with-streaming) documentation.*\n\nIn Apigee, the default behavior is that HTTP request and response payloads are stored in an\nin-memory buffer before they are processed by the policies in the API Proxy.\n\nIf streaming is enabled, then request and response payloads are streamed without modification to\nthe client app (for responses) and the target endpoint (for requests). Streaming is useful\nespecially if an application accepts or returns large payloads, or if there's an application that\nreturns data in chunks over time.\n\nAntipattern\n-----------\n\nAccessing the request/response payload with streaming enabled causes Apigee to go back to the\ndefault buffering mode.\n**Figure 1**: Accessing request/response payload with streaming enabled\n\nThe illustration above shows that we are trying to extract variables from the request payload and\nconverting the JSON response payload to XML using JSONToXML policy. This will disable the streaming\nin Apigee.\n\nImpact\n------\n\n- Streaming will be disabled which can lead to increased latencies in processing the data\n- Increase in the heap memory usage or `OutOfMemory` errors can be observed on Message Processors due to use of in-memory buffers especially if we have large request/response payloads\n\nBest practice\n-------------\n\n- Don't access the request/response payload when streaming is enabled.\n\nFurther reading\n---------------\n\n- [Streaming requests and responses](/apigee/docs/api-platform/develop/enabling-streaming)\n- [How does Apigee streaming work?](https://www.googlecloudcommunity.com/gc/Apigee/How-does-APIGEE-Edge-Streaming-work/td-p/38511)\n- [How to handle streaming data together with normal request/response payload in a single API Proxy](https://www.googlecloudcommunity.com/gc/Apigee/How-to-handle-streaming-data-together-with-normal-request/m-p/49986)\n- [Best practices for API proxy design and development](/apigee/docs/api-platform/fundamentals/best-practices-api-proxy-design-and-development)"]]