smrchy / rsmq

Redis Simple Message Queue
MIT License
1.76k stars 125 forks source link

no message == empty queue? #138

Closed whyvez closed 3 years ago

whyvez commented 3 years ago

Is it safe to assume that if no message is returned from receiveMessage that the queue is empty?

I am using the following logic:

const { id, message } = await rsmq.receiveMessage({ qname });
if (!message) {
  log.info('Successfully processed queue.');
  process.exit(0);
}

In my case, the process exits prematurely before the queue is empty, how could this happen?

exinferis commented 3 years ago

Since messages have a visibility timeout after being received they still remain in the queue but are not delivered, when using receiveMessage. So no - it is wrong to assume for the queue to be empty just because you don't retrieve a message currently. getQueueAttributes should give you insights of the selected queue including the total message count.