How do I disable response buffering in API Management and force immediate flush?

1.2k views Asked by At

I have a http triggered Azure Function with a canned response returning a collection of json objects. The response is flushed every 10 objects with a 2 second delay in between.

When calling this endpoint directly to the Function I receive the flushed response immediately with no buffering - 10 complete objects with a 2 second delay.

When I call this endpoint through Azure's APIM the response is no longer flushed immediately. I get partial objects and the response appears to be hitting a buffer which is only flushed after a certain time or size.

How can I force APIM to not buffer the response?

2

There are 2 answers

0
MrPanucci On BEST ANSWER

I was able to get a response from Microsoft on an undocumented attribute to disable response buffering. Yet to test this extensively yet, but appears to work.

<backend>
   <forward-request buffer-response="false" />
</backend>
1
Joey Cai On

When you forward request, set buffer-request-body="false" which will disable buffer request.

<forward-request timeout="time in seconds" follow-redirects="false | true" buffer-request-body="false" fail-on-error-status-code="false | true"/>

Also, do not use <set-body> policy. The inner text of the set-body is buffered in a memory stream and delivered to the recipient.