Try It: Topic Pattern Matcher
Try Change binding pattern 1 to sensor.*.zone1.
Observe Watch Pattern 1 in Pattern Match Results and the message routed to matching queues.
Explain Describe how Pattern 1 uses * to match exactly one dot-separated word.
Play routing
Reset
Technical boundaries. The tool evaluates one routing key against 3 binding patterns. Matching uses dot-separated words, with * for one word and # for zero or more words.
viewof testRoutingKey = Inputs. text ({
value : "sensor.temperature.zone1" ,
label : "Enter a routing key:" ,
placeholder : "e.g. sensor.humidity.zone2"
})
viewof bindingPattern1 = Inputs. text ({
value : "sensor.temperature.#" ,
label : "Binding pattern 1:" ,
placeholder : "e.g. sensor.temperature.#"
})
viewof bindingPattern2 = Inputs. text ({
value : "sensor.*.zone1" ,
label : "Binding pattern 2:" ,
placeholder : "e.g. sensor.*.zone1"
})
viewof bindingPattern3 = Inputs. text ({
value : "sensor.#" ,
label : "Binding pattern 3:" ,
placeholder : "e.g. sensor.#"
})
topicMatch = {
function matchTopic (routingKey, pattern) {
const rkParts = routingKey. split ('.' );
const patParts = pattern. split ('.' );
let ri = 0 , pi = 0 ;
while (ri < rkParts. length && pi < patParts. length ) {
if (patParts[pi] === '#' ) {
if (pi === patParts. length - 1 ) return true ;
pi++;
for (let k = ri; k <= rkParts. length ; k++ ) {
if (matchTopic (rkParts. slice (k). join ('.' ), patParts. slice (pi). join ('.' ))) return true ;
}
return false ;
} else if (patParts[pi] === '*' ) {
ri++;
pi++;
} else if (patParts[pi] === rkParts[ri]) {
ri++;
pi++;
} else {
return false ;
}
}
if (pi < patParts. length && patParts[pi] === '#' && pi === patParts. length - 1 ) return true ;
return ri === rkParts. length && pi === patParts. length ;
}
const patterns = [
{label : "Pattern 1" , pattern : bindingPattern1},
{label : "Pattern 2" , pattern : bindingPattern2},
{label : "Pattern 3" , pattern : bindingPattern3}
];
return patterns. map (p => ({
... p,
matches : matchTopic (testRoutingKey. trim (), p. pattern . trim ())
}));
}
matchCount = topicMatch. filter (m => m. matches ). length
html `<div style="background: #f8f9fa; border-left: 4px solid #16A085; padding: 15px; margin-top: 15px; font-family: Arial, sans-serif;">
<h4 style="color: #2C3E50; margin-top: 0;">Pattern Match Results</h4>
<div style="margin-bottom: 10px; color: #7F8C8D; font-size: 13px;">
Routing key <code style="background: #2C3E50; color: white; padding: 2px 6px; border-radius: 3px;"> ${ testRoutingKey} </code> is evaluated against ${ topicMatch. length } binding patterns:
</div>
${ topicMatch. map (m => `
<div style="display: flex; align-items: center; gap: 10px; padding: 10px; margin-bottom: 6px; background: ${ m. matches ? '#e8f8f5' : '#fdf2f2' } ; border-radius: 4px; border-left: 4px solid ${ m. matches ? '#16A085' : '#E74C3C' } ;">
<div style="width: 80px; color: #7F8C8D; font-size: 12px; font-weight: bold;"> ${ m. label } </div>
<code style="flex: 1; background: white; padding: 4px 8px; border-radius: 3px; font-size: 13px;"> ${ m. pattern } </code>
<div style="width: 90px; text-align: center; font-weight: bold; color: ${ m. matches ? '#16A085' : '#E74C3C' } ; font-size: 14px;">
${ m. matches ? 'MATCH' : 'NO MATCH' }
</div>
</div>
` ). join ('' )}
<div style="margin-top: 12px; padding: 10px; background: linear-gradient(135deg, #16A085 0%, #3498DB 100%); border-radius: 4px; color: white; text-align: center;">
<span style="font-size: 14px;">Message routed to <strong> ${ matchCount} </strong> of 3 queues</span>
${ matchCount === 0 ? '<div style="font-size: 12px; opacity: 0.9; margin-top: 4px;">Warning: Unroutable message (no matching bindings). Consider adding a fallback queue with pattern #.</div>' : '' }
</div>
<div style="margin-top: 10px; color: #7F8C8D; font-size: 12px;">
<strong>Wildcard reference:</strong> <code>*</code> matches exactly one word | <code>#</code> matches zero or more words | Words are dot-separated
</div>
</div>`
Back to the chapter