node-ts / bus

A typescript based enterprise service bus framework based on enterprise integration patterns
https://bus.node-ts.com/
MIT License
270 stars 26 forks source link

#175 - Fix high cpu for rabbitmq consumers #176

Closed adenhertog closed 2 years ago

adenhertog commented 2 years ago

This is a fix for #175 where a consumer of an empty rabbitmq queue will see high CPU. This is due to an implementation that relied on amqplib's channel.get() that returns immediately regardless if a message is queued or not. As a result this was being called repeatedly causing the high CPU spin (evidenced by less CPU when a .sleep() was added)

This change uses .consume() instead which is callback based and only triggers when a message is available for consumption. As a result there is no repeated spinning waiting for a message.