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.

H S
  • 103
  • 13
  • 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? – Harshita Singh Aug 17 '20 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... – H S Aug 18 '20 at 10:45

1 Answers1

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.

Harshita Singh
  • 4,590
  • 1
  • 10
  • 13
  • 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(...). – H S Aug 18 '20 at 20:53
  • 1
    This is not possible to achieve using Function apps, but you can consider the High level idea I mentioned above. – Harshita Singh Aug 19 '20 at 09:01
  • 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. – H S Aug 19 '20 at 10:41
  • If this response answers your question, could you mark it as answer to help the community? – Harshita Singh Aug 19 '20 at 12:37