简体   繁体   中英

Azure Functions Keeping HTTP Connection Alive

I've been struggling to find any kind of information related to the issue I'm experiencing with Azure Functions (Node.js).

I'm attempting to keep a HTTP request/connection alive and start a text/stream on initial request and the write chunks to this stream without terminating the connection.

Whilst I could do this with a standard express + Node.js process/server with response.write(...).

I can't seem to find the equivalent in Azure's context.res object neither can I prevent Azure Functions from invoking context.res.done() instead just writing chunks to the active stream.

I'm trying to build a solution that allows me to perform long polling...

I'd very much appreciate any advice or information.

Thank you very much.

Update:

To anyone who stumbled upon this question. It's not possible to do anything but a whole http request/response. Hopefully streaming data directly from an Azure function is supported in the future.

Azure Functions is a serverless compute service that lets you run event-triggered code without having to explicitly provision or manage infrastructure.

And as Azure Functions are serverless, you cannot send different Http Requests to same function instance as you don't have control on the servers and they are internally managed.

My high level suggestion to solve this problem is (a loosely coupled solution): Have a memory/DB where your first function app can save all the chunks until they are picked up by second function app , which merges all the chunks of a stream and sends to the final destination. Once all the chunks are saved to memory/DB by the first function app , you can send a message to any publish/subscribe service (like Event Grid) which then triggers the second function app . You can have schema like this for your memory/DB - ChunkID (PK), StreamID, ChunkStream, SequenceNo, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM