ssut / nestjs-sqs

A project to make SQS easier to use within NestJS, with decorator-based handling and seamless NestJS-way integration.
MIT License
215 stars 53 forks source link

Empty event does not work #4

Closed hdiaz-nectia closed 3 years ago

hdiaz-nectia commented 3 years ago

Hi,

I need to know when the queue is empty, I'm trying to do reading the docs at https://github.com/bbc/sqs-consumer#options:

  @SqsConsumerEventHandler(`${process.env.QUEUE_NAME}`, 'processing_error')
  public onProcessingError(error: Error, message: AWS.SQS.Message) {   
    console.error(`Error reading message`, JSON.stringify(error));
  }

  @SqsConsumerEventHandler(`${process.env.QUEUE_NAME}`, 'empty')
  public onEmpty() {   
    console.log(`The queue is empty!`);    
  }

The problem is that this log message is never printed to console. I've tried to test it adding messages to local queue and waiting for de empty event.

I use softwaremill/elasticmq docker image to run locally my queue.

I debug the library and I think the problem is in file sqs.services.js:

const eventMetadata = eventHandlers.find(({ meta }) => meta.name === name);

The find method get only first event, If I change order, empty event first in my class, the event empty is fired but the second not.

hdiaz-nectia commented 3 years ago

fix in new version