sqs-consumer icon indicating copy to clipboard operation
sqs-consumer copied to clipboard

app consuming more than one message at a time, in single-message (not batch) mode

Open upugo-dev opened this issue 7 years ago • 9 comments

Hi,

My app seems to consume and process messages simultaneously, even though I am using handleMessage option not handleMessageBatch().

It is really important to my application that messages are consumed one-at-a-time

upugo-dev avatar May 20 '19 12:05 upugo-dev

If you're using handleMessage and you're using the default batch size (1) but then messages won't be processed simultaneously.

nspragg avatar May 20 '19 13:05 nspragg

I wasn't setting the batchSize anywhere in my application, so the default should be 1, right? I have inspected using DEBUG=sqs-consumer in my .env and I am definitely receiving message B before message A's handleMessage function has resolved

upugo-dev avatar May 20 '19 13:05 upugo-dev

You're not spawning workers (manually or using pm2, for example), running on multiple redundant servers or running the process multiple times? In those cases you will experience messages being consumed "simultaneously".

scripter-co avatar May 20 '19 13:05 scripter-co

The plan in production is to spawn multiple workers pointing at the same queue yes, but right now I am just testing locally on one machine with a simple sleep(5000) function in the handleMessage!

upugo-dev avatar May 20 '19 13:05 upugo-dev

can you post your handlers code?

scripter-co avatar May 20 '19 13:05 scripter-co

handleSQS.js

const handleSQSMessage = async (message) => {
  const sleep = new Promise((resolve, reject) => {
    setTimeout(() => resolve('done!'), 5000);
  });
  return await sleep;
};

index.js

const sqsapp = Consumer.create({
  queueUrl: auditQueueURL,
  messageAttributeNames: ['All'],
  attributeNames: ['All'],
  handleMessage: handleSQSMessage,
  visibilityTimeout: process.env.MSG_EXTENSION_TIME,
  handleMessageTimeout: process.env.MSG_TOTAL_TIME_LIMIT,
  batchSize: 1,
});

upugo-dev avatar May 20 '19 13:05 upugo-dev

Hey, can anyone help me here? I need to await inside the handleMessage function, and not pick up any more messages until the handleMessage has either rejected or resolved. How can I achieve this?

upugo-dev avatar May 20 '19 17:05 upugo-dev

Closing issue since #167 has been raised.

nspragg avatar May 21 '19 07:05 nspragg

I can attest that this issue has NOT been resolved. Please see https://github.com/bbc/sqs-consumer/issues/256

adamleemiller avatar Apr 27 '21 08:04 adamleemiller