Antipattern: accesso al payload della richiesta/risposta quando lo streaming è abilitato
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Stai visualizzando la documentazione di Apigee e Apigee hybrid.
Visualizza la documentazione di
Apigee Edge.
In Apigee, il comportamento predefinito prevede che i payload delle richieste e delle risposte HTTP vengano memorizzati in un buffer in memoria prima di essere elaborati dalle norme in API Proxy.
Se lo streaming è abilitato, i payload di richiesta e risposta vengono trasmessi in streaming senza modifiche all'app client (per le risposte) e all'endpoint di destinazione (per le richieste). Lo streaming è utile soprattutto se un'applicazione accetta o restituisce payload di grandi dimensioni oppure se esiste un'applicazione che restituisce i dati in blocchi nel tempo.
Antipattern
L'accesso al payload di richiesta/risposta con lo streaming abilitato fa sì che Apigee torni alla modalità di buffering predefinita.
Figura 1: accesso al payload di richiesta/risposta con lo streaming abilitato
L'illustrazione sopra mostra che stiamo tentando di estrarre le variabili dal payload della richiesta e di convertire il payload della risposta JSON in XML utilizzando il criterio JSONToXML. Lo streaming verrà disattivato
in Apigee.
Impatto
Lo streaming verrà disattivato, il che può comportare un aumento delle latenze nell'elaborazione dei dati
È possibile osservare un aumento dell'utilizzo della memoria heap o errori OutOfMemory nei Message Processors
a causa dell'utilizzo di buffer in memoria, in particolare se i payload di richiesta/risposta sono di grandi dimensioni
Best practice
Non accedere al payload della richiesta/risposta quando lo streaming è abilitato.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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)"]]