viewof routingKey = Inputs.text({
label: "Routing Key (use dots to separate words)",
value: "sensor.temp.line1.m03",
placeholder: "e.g., alert.critical.l2.m15",
width: 220
})
viewof bindingPattern1 = Inputs.text({
label: "Binding Pattern 1 (* = one word, # = zero or more words)",
value: "sensor.temp.#",
placeholder: "e.g., sensor.*.line1",
width: 220
})
viewof bindingPattern2 = Inputs.text({
label: "Binding Pattern 2",
value: "sensor.#",
placeholder: "e.g., *.*.line1.*",
width: 220
})
viewof bindingPattern3 = Inputs.text({
label: "Binding Pattern 3",
value: "sensor.*.*.m03",
placeholder: "e.g., alert.critical.#",
width: 220
})
// Topic pattern matching function (* = exactly one word, # = zero or more words)
function matchesPattern(key, pattern) {
const keyParts = key.split('.');
const patternParts = pattern.split('.');
const match = (k, p) => {
if (p === patternParts.length) return k === keyParts.length;
if (patternParts[p] === '#') {
for (let i = k; i <= keyParts.length; i++) {
if (match(i, p + 1)) return true;
}
return false;
}
if (k === keyParts.length) return false;
return (patternParts[p] === '*' || patternParts[p] === keyParts[k]) && match(k + 1, p + 1);
};
return match(0, 0);
}
match1 = matchesPattern(routingKey, bindingPattern1)
match2 = matchesPattern(routingKey, bindingPattern2)
match3 = matchesPattern(routingKey, bindingPattern3)
matchCount = [match1, match2, match3].filter(m => m).length
html`<div style="background: #f8f9fa; padding: 20px; border-left: 4px solid #3498DB; margin: 20px 0; border-radius: 4px;">
<h4 style="color: #2C3E50; margin-top: 0;">Pattern Matching Results</h4>
<div style="background: white; padding: 15px; border-radius: 4px; margin-bottom: 15px; border: 2px solid #3498DB;">
<div style="color: #7F8C8D; font-size: 0.9em; margin-bottom: 5px;">Routing Key:</div>
<div style="color: #2C3E50; font-size: 1.2em; font-weight: bold; font-family: monospace;">${routingKey}</div>
</div>
<div style="display: grid; gap: 10px;">
${[
{ pattern: bindingPattern1, match: match1, queue: "Queue 1" },
{ pattern: bindingPattern2, match: match2, queue: "Queue 2" },
{ pattern: bindingPattern3, match: match3, queue: "Queue 3" }
].map(({ pattern, match, queue }) => `
<div style="background: ${match ? '#d4edda' : '#f8d7da'}; padding: 12px; border-radius: 4px; border-left: 4px solid ${match ? '#16A085' : '#E74C3C'};">
<div style="display: flex; justify-content: space-between; align-items: center;">
<div>
<div style="font-weight: bold; color: #2C3E50; margin-bottom: 3px;">${queue}</div>
<div style="font-family: monospace; color: #2C3E50; font-size: 0.95em;">${pattern}</div>
</div>
<div style="font-size: 1.5em; font-weight: bold; color: ${match ? '#16A085' : '#E74C3C'};">
${match ? '✓ MATCH' : '✗ NO MATCH'}
</div>
</div>
</div>
`).join('')}
</div>
<div style="background: ${matchCount > 0 ? 'linear-gradient(135deg, #16A085 0%, #2C3E50 100%)' : 'linear-gradient(135deg, #E67E22 0%, #E74C3C 100%)'}; color: white; padding: 15px; border-radius: 4px; text-align: center; margin-top: 15px;">
<div style="font-size: 0.9em; opacity: 0.9; margin-bottom: 5px;">Message Delivery Summary</div>
<div style="font-size: 2em; font-weight: bold;">${matchCount} ${matchCount === 1 ? 'Queue' : 'Queues'}</div>
<div style="font-size: 0.85em; opacity: 0.9;">will receive this message</div>
</div>
<div style="margin-top: 15px; padding: 12px; background: white; border-radius: 4px; font-size: 0.85em; color: #2C3E50; border: 1px solid #ddd;">
<strong>Pattern Matching Rules:</strong><br>
• <code>*</code> (asterisk) matches exactly one word<br>
• <code>#</code> (hash) matches zero or more words<br>
• Words are separated by dots (.)<br>
• Example: <code>sensor.*.#</code> matches <code>sensor.temp</code> and <code>sensor.temp.line1.machine03</code> but not <code>sensor</code>
</div>
</div>`Topic Exchange Pattern Matching
Topic Exchange Pattern Matching
animation
amqp
protocols
messaging
Try Change binding pattern 1 to sensor.*.line1.
Observe Watch Queue 1 in pattern matching Results and the Message Delivery Summary.
Explain Explain why sensor.temp.line1.m03 does not match sensor.*.line1 for Queue 1.
Technical boundaries. The tool evaluates one routing key against 3 binding patterns. A single message can route to multiple queues if multiple patterns match.