Azure Functions [JavaScript / Node.js] - HTTP call, best practice

From my Azure function (which works in Node.js, called by the EventHub message), I would like to make a request to send to an external page. Sort of:

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 doubt it is not antipattern.

Imagine a situation when thousands of functions are launched in a short time - for each execution we need to create an HTTP client and create a connection ...

From short research, I found some solution for C # Azure functions: https://docs.microsoft.com/en-us/azure/architecture/antipatterns/improper-instantiation/ which uses the static HttpClient class.

, Node.js Azure Function? , Node.js Azure?

+4
1

, , http.globalAgent Agent

HTTP-. , , , , , . , keepAlive.

: https://nodejs.org/api/http.html#http_class_http_agent

http.globalAgent.maxSockets , , , , , . , , keep-alive globalAgent/Agent, .

+2

Source: https://habr.com/ru/post/1691110/


All Articles