From my Azure Function (which runs in Node.js, triggered by EventHub message) I would like to make a post request to some external page. Something like:
module.exports = function (context, eventHubMessages) {
var http = require("http");
context.log('JavaScript Function triggered by eventHub messages ');
http.request(post_options, function(res){
...
})
context.done();
The code above will probably work but I have a doubt if that is not an antipattern.
Imagine situation when there are thousands of functions triggered in short period of time - for each execution we would need to create an HTTP client and create a connection...
From short research I have found some solution proposal for C# Azure Functions: https://learn.microsoft.com/en-us/azure/architecture/antipatterns/improper-instantiation/ which uses static HttpClient class.
I have a question, is there any similar approach in Node.js Azure Function? Or any other way to avoid this problem, to share an object between Node.js Azure Function executions?
requireout of function, andcontext.doneinside the callback.