javascript - Correct way to do node long polling -
seems there's lot of discussion how haven't found concrete examples. node application accessing restful api going pass through database. initial solution
function getrecord() { var req = https.request(options, function(res){ res.on('data', function(data) { var record = json.parse(data.tostring('utf-8')); //do database things on getrecord(); }); }); req.write(querystring); req.end(); }
this accomplishes want. i'm going keep getting new records api, i'm not sure if best approach doing want.
one (especially favorable) alternative switch bus architecture message server such rabbitmq.
you need either control api or have api can register callbacks with.
long polling strategy can degrade performance , bloat logs quite quickly. event driven methods, i've listed above, preferred if possibility. and, unlike long polling, event driven strategies don't introduce latency. if latency concern, more frequent poll, more degrade performance , bloat logs.
Comments
Post a Comment