接收从Node.JS到Azure事件中心的HTTPS请求的ECONNRESET错误

我目前有一个Node.js Web API,它将HTTPS请求发送到Azure事件中心。 如果我发送单个请求或小的突发(5-7),集线器收到罚款。 但是,如果我尝试发送比这更多的信息,那么我将会收到来自集线器的ECONNRESET错误,这个错误超过了ECONNRESET (第一个ECONNRESET将通过罚款)。 (7是不是一个硬数字,它从testing到testing,但似乎是在附近)

我有一个JSON对象的数组,我通过下面的代码发送到集线器:

 for (var i in stack) { var obj = stack[i]; sendPayloadToEventHub(JSON.stringify(obj)); } 

将JSON发送到事件中心的代码:

 sendPayloadToEventHub = function (payload) { var options = { hostname: config['namespace'] + '.servicebus.windows.net', port: 443, path: '/' + config['hubname'] + '/publishers/' + config['devicename'] + '/messages', method: 'POST', headers: { 'Authorization': returnSASToken(), 'Content-Length': payload.length, 'Content-Type': 'application/atom+xml;type=entry;charset=utf-8' } }; // create the request object with the set options var req = https.request(options, function (res) { res.on('data', function (d) { process.stdout.write(d); }); res.on('end', function () { console.log('log complete....'); }); }); // Error Handle req.on('error', function (e) { console.error('HTTPS error: ' + e); }); // Deliver the payload and end the request req.write(payload); req.end(); }; 

我收到HTTPS error: Error: read ECONNRESET的输出HTTPS error: Error: read ECONNRESET未能传递的消息的HTTPS error: Error: read ECONNRESET

该数组可以有任何数量的JSON对象,所以我需要能够发送不同数量的突发。 我曾尝试在循环中添加睡眠延迟,但是没有解决这个问题。

有谁知道可能是什么原因造成的?

这个错误是由于一些JSON对象的payload.length不能正确计算的结果。 确定计算后,错误停止。