bullmq
bullmq copied to clipboard
Wildcard option for custom events
BullMQ has an option to use custom events: https://docs.bullmq.io/guide/events/create-custom-events
I wish there was a way to listen to all the events via catch-all/wildcard listener.
const producer = new QueueEventsProducer('eventStream');
// Create consumer
const consumer = new QueueEvents('eventStream');
consumer.on('*', (eventName, eventData) => {
console.log(`Received event: ${eventName}`, eventData);
});
My use case is to handle all events, check metadata and call specific handler.
I tried generic events but they don't work for some reason. Don't know if this is expected or not.
consumer.on('complete', (eventName, eventData) => {
console.log(`Received event: ${eventName}`, eventData);
});
Related to: https://github.com/taskforcesh/bullmq/issues/831
A second though here: maybe wildcard is not the best design. It is intuitive, but adds special asterisk character that can lead to unintended bugs.
I think it is better to have a dedicated method like this
consumer.onAll(({ eventName, data }) => {
console.log(`Received event: ${eventName}`, data);
})