1

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.

2
  • Do you mean that you get chunks of data on the same Azure Function app instance from a source and you keep appending them to your global variable and once you get all the chunks of data, you return all of it at once? Commented Aug 17, 2020 at 18:44
  • @HarshitaSingh-MSFT Correct. Data could be available within a few minutes up to possibly 5 minutes but I need the http request to the function app to stay connected and alive until then... Commented Aug 18, 2020 at 10:45

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Hey, thanks very much for the response. My bad for being so convoluted! Essentially all I want is to hold a connection open for a few minutes. So when you make a http request to /api/notifications it keeps that request alive for a few minutes instead of immediately returning with context.done(...).
This is not possible to achieve using Function apps, but you can consider the High level idea I mentioned above.
Exactly. I was just confirming whether there was a way to work around this whole http request/response restriction. Thanks for the information though I appreciate it.
If this response answers your question, could you mark it as answer to help the community?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.