Use wildcards in topic subscriptions
masterMQEmitter supports topic matching using wildcards separated by the configured separator (default /).
Single Level Wildcard (+)
Matches exactly one word. By default, it matches non-empty words, but if matchEmptyLevels is set to true, it also matches empty levels (e.g., //).
Multi-Level Wildcard (#)
Matches zero or more words at the end of a topic path.
Examples
Single level (+) matching:
// Matches 'hello/my/world' but NOT 'hello/world'
emitter.on('hello/+/world', (msg, done) => {
done()
})Multi-level (#) matching:
// Matches 'hello/my/world', 'hello/my/world/extra', and 'hello/world'
emitter.on('hello/#', (msg, done) => {
done()
})
// Matches everything
emitter.on('#', (msg, done) => {
done()
})const mq = require('mqemitter')
const emitter = mq()
// Single level wildcard
emitter.on('hello/+/world', function(message, cb) {
cb()
})
// Multi-level wildcard
emitter.on('hello/#', function(message, cb) {
cb()
})
// Mix and match
emitter.on('a/+/b/#', function(message, cb) {
cb()
})