Comments (4)
We've not been able to reproduce this issue. Tested using the following script, varying the number of consumer instances and batchsize. After each test, all messages were dequeued. No errors.
Test script:
'use strict';
const Consumer = require('sqs-consumer');
const QUEUE = ''; // removed intentionally
function createConsumer() {
return Consumer.create({
queueUrl: QUEUE,
batchSize: 1,
handleMessage: function (message, done) {
console.log(message);
done();
}
});
}
function startMultipleConsumers(n) {
for (let i = 0; i < n; i++) {
const consumer = createConsumer();
consumer.on('error', function (err) {
console.log(err.message);
});
consumer.start();
console.log('started consumer...');
}
}
// startMultipleConsumers(10);
// startMultipleConsumers(100);
startMultipleConsumers(1000);
from sqs-consumer.
Closing issue - if further discussion is required, will reopen.
from sqs-consumer.
I am having the same issue. @nspragg your example works ok. But I am using a collection to hold all created consumers so I can stop some of them similar to how @edeliu2000 is using an array. Even with 3 consumers for same queue and 1k messages the consumer gets crazy.
- Some messages are not sent to the handler function even though consumed from the queue.
- Polling continues even though not all done were called so messages are overlapping.
I am not sure exactly what happens but my best guess is that it has something to do with the async series. Someone is messing the references for done or for the handleMessage if you save multiple consumers in an array or collection.
I was creating the objects in a loop then starting the consumers in another loop. I busted my head around this for several days now and I cannot understand what happens. I just used the logic in your example and it works fine but this means that I have no reference to created consumers and no control over stopping them.
It's pretty hard to post all my code and logic, but please let me know if I can help you with anything in resolving this issue.
Thanks
from sqs-consumer.
@unDemian had a similar use case. haven't tested extensively but so far this works. I took the snippet w/ the for loop and just added an eventEmitter
in the upper scope to keep track of stuff
adapting previous example
'use strict';
const Consumer = require('sqs-consumer');
const QUEUE = ''; // removed intentionally
const events = require('events')
const killSignalEmitter = new events.EventEmitter()
function createConsumer() {
return Consumer.create({
queueUrl: QUEUE,
batchSize: 1,
handleMessage: function (message, done) {
console.log(message);
done();
}
});
}
const startMultipleConsumers = (n) => {
for (let i = 0; i < totalWorkers; i++) {
const consumer = createConsumer()
consumer.on('error', (err) => {
console.error(err)
})
consumer.start()
// listen for kill message from upper scope
killSignalEmitter.on('killSwitch', () => {
console.log("KILL RECEIVED")
consumer.stop()
})
// notify upper scope that a worker has finished shutting down
consumer.on('stopped', () => {
console.log('Finished queue shutdown')
killSignalEmitter.emit('workerDown')
})
}
}
var totalWorkers = 1000
var deadWorkers = 0
// intercept kill signal and shutdown workers gracefully
process.on('SIGINT', () => {
console.log('Starting queue shutdown')
killSignalEmitter.emit('killSwitch')
})
// tally our casualties. when all workers have shuffled off mortal coil, shut her down
killSignalEmitter.on('workerDown', () => {
deadWorkers++
if (deadWorkers >= totalWorkers) process.exit(0)
})
startMultipleConsumers(totalWorkers);
from sqs-consumer.
Related Issues (20)
- Trigger a debug message periodically while the consumer is processing messages HOT 1
- Remove debug module in favour of node in-builts HOT 1
- [Bug]: TypeError: Cannot set property message of [object Object] which has only a getter HOT 7
- handleMessage does not allow for an injected process method HOT 3
- [Feature]: Support none standard errors - "Cannot set property message of which has only a getter" HOT 7
- Drop support for Node 16 HOT 2
- [Bug]: High CPU usage HOT 1
- create a version of consumer with the aws sdk version for json HOT 3
- [Bug]: SQS receive message failed: Could not load credentials from any providers HOT 2
- [Bug]: Undocumented breaking change - acknowledgment to handleMessage HOT 7
- v5.8.0 if send message to sqs queue on other pc HOT 2
- [Bug]: ApproximateReceiveCount is not part of QueueAttributeName HOT 4
- The automated release is failing 🚨 HOT 1
- [Bug]: Version 8.1.5 of this library incompatible with @aws-sdk/client-sqs version 3.507.0 HOT 5
- Add a link to the docs at the top of the readme HOT 2
- Remove AWS SDK V2 Note
- Upgrade p-event to v6 HOT 1
- Upgrade chai to v5 HOT 1
- Remove the `handler_processing` debugger HOT 2
- [Bug]: CredentialsProviderError is not treated as a connection error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqs-consumer.