weyoss / redis-smq

A simple high-performance Redis message queue for Node.js.
MIT License
588 stars 64 forks source link

what is the cb function? #35

Closed darrenli2 closed 4 years ago

darrenli2 commented 4 years ago

How do I define the db function? Does this work?


const redisSMQ = require('redis-smq');
const ingestion = require('./ingestion');

const { Consumer } = redisSMQ;

class QueueConsumer extends Consumer {
  // eslint-disable-next-line class-methods-use-this
  consume(message, cb) {
    ingestion.myfunction(message);
    cb();
  }
}

module.exports = { QueueConsumer };

And also how do we check if the queue is empty?
weyoss commented 4 years ago

I apologize for my late response.

The callback fn is provided by the message queue to acknowledge/unacknowledge your message. In other words, it is the way that you can tell the MQ that your message has been either successfully consumed or not.

Please refer to:

for more details.

weyoss commented 4 years ago

Regarding your second question, at the API level of the MQ there is no method to check if the queue is empty or not.

Using the RedisSMQ monitor of course you have any information you need (including queues size) about all of your queues, consumers and producers.