bullmq icon indicating copy to clipboard operation
bullmq copied to clipboard

Wildcard option for custom events

Open Mihailoff opened this issue 5 months ago • 2 comments

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);
});

Mihailoff avatar Jul 07 '25 18:07 Mihailoff

Related to: https://github.com/taskforcesh/bullmq/issues/831

Mihailoff avatar Jul 07 '25 18:07 Mihailoff

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);
})

Mihailoff avatar Jul 07 '25 22:07 Mihailoff