'How to implement redis streams with nodejs?

I am going to implement a Redis stream to serve has a message queue / message broker and I was asking myself about the structure of the NodeJs code that will serve that purpose. I mean, knowing that the objective is to continue to consume messages over and over again I do not see a clean way to do this other than :

while(true){
    >get a message from stream with a blocker XREADGROUP BLOCK ...
    >do some magic
    >acknowledge magic is done XACK ...
}

Because I think any recursive function will create more and more instances of the running function and a pretty massive memory / computational leak.

Any other ideas ? Am I missing something ?

(Of course I intend to do it in a NodeJs cluster and I already made a boilerplate code to manage consumers etc so I'm just asking about the structure of workers' code here)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source