viewof debugRoutingKey = Inputs.text({
value: "sensor.temperature.zone1",
label: "Producer routing key:",
placeholder: "e.g. sensor.temperature.zone1"
})
viewof debugBindingKey = Inputs.text({
value: "sensor.temp.#",
label: "Consumer binding pattern:",
placeholder: "e.g. sensor.temp.#"
})
viewof debugExchangeType = Inputs.select(
["direct", "topic"],
{value: "topic", label: "Exchange type:"}
)Try It: Routing Key Debugger
Try It: Routing Key Debugger
animation
amqp
protocols
messaging
Try Change Consumer binding pattern: to sensor.temperature.#, then press Check routing.
Observe Watch Routing Debug Analysis and WORD-BY-WORD COMPARISON after Check routing.
Explain Describe how topic and direct exchange matching differ after Check routing.
Technical boundaries. Direct exchange uses exact string comparison. Topic matching compares the complete pattern: * matches exactly one word, and # matches zero or more words, including before later pattern words.
NoteTry It: Routing Key Debugger
debugResult = {
const rk = debugRoutingKey.trim();
const bk = debugBindingKey.trim();
if (debugExchangeType === "direct") {
const matches = rk === bk;
return {
matches,
reason: matches
? `Exact match: "${rk}" equals "${bk}".`
: `No match: "${rk}" does not exactly equal "${bk}".`,
rkParts: rk.split('.'),
bkParts: bk.split('.'),
partComparison: null
};
}
// Match the complete topic pattern. AMQP 0-9-1 permits # before later words,
// so try every possible number of words for that wildcard.
const rkParts = rk.split('.');
const bkParts = bk.split('.');
let deepestFailure = null;
const rememberFailure = (ri, bi, trace, step) => {
const candidate = { depth: trace.length, words: ri, trace: [...trace, step] };
if (!deepestFailure || candidate.depth > deepestFailure.depth ||
(candidate.depth === deepestFailure.depth && candidate.words > deepestFailure.words)) {
deepestFailure = candidate;
}
};
const walk = (ri, bi, trace) => {
if (bi === bkParts.length) {
if (ri === rkParts.length) return trace;
const extra = rkParts.length - ri;
rememberFailure(ri, bi, trace, {
rk: rkParts.slice(ri).join('.'), bk: '(end of pattern)', status: 'fail',
note: `Routing key has ${extra} extra word(s)`
});
return null;
}
const word = bkParts[bi];
if (word === '#') {
for (let end = ri; end <= rkParts.length; end++) {
const count = end - ri;
const step = {
rk: count ? rkParts.slice(ri, end).join('.') : '(zero words)',
bk: '#', status: 'match', note: `# matches ${count} word(s)`
};
const result = walk(end, bi + 1, [...trace, step]);
if (result) return result;
}
return null;
}
if (ri >= rkParts.length) {
rememberFailure(ri, bi, trace, {
rk: '(end of key)', bk: word, status: 'fail', note: 'Pattern needs more words'
});
return null;
}
if (word === '*' || word === rkParts[ri]) {
return walk(ri + 1, bi + 1, [...trace, {
rk: rkParts[ri], bk: word, status: 'match',
note: word === '*' ? '* matches exactly one word' : 'Exact word match'
}]);
}
rememberFailure(ri, bi, trace, {
rk: rkParts[ri], bk: word, status: 'fail',
note: `Word mismatch at position ${ri + 1}: "${rkParts[ri]}" ≠ "${word}"`
});
return null;
};
const matchedPath = walk(0, 0, []);
const matches = matchedPath !== null;
return {
matches,
reason: matches ? 'All pattern words match the routing key.' : deepestFailure.trace.at(-1).note,
rkParts,
bkParts,
partComparison: matches ? matchedPath : deepestFailure.trace
};
}
html`<div style="background: #f8f9fa; border-left: 4px solid #E67E22; padding: 15px; margin-top: 15px; font-family: Arial, sans-serif;">
<h4 style="color: #2C3E50; margin-top: 0;">Routing Debug Analysis</h4>
<div style="padding: 12px; margin-bottom: 12px; background: ${debugResult.matches ? '#e8f8f5' : '#fdf2f2'}; border: 2px solid ${debugResult.matches ? '#16A085' : '#E74C3C'}; border-radius: 4px; text-align: center;">
<div style="font-size: 20px; font-weight: bold; color: ${debugResult.matches ? '#16A085' : '#E74C3C'};">
${debugResult.matches ? 'MATCH - Queue Binding Matches' : 'NO MATCH - This Binding Misses'}
</div>
<div style="font-size: 13px; color: #2C3E50; margin-top: 4px;">${debugResult.reason}</div>
</div>
${debugResult.partComparison ? `
<div style="background: white; padding: 12px; border-radius: 4px; border: 1px solid #e0e0e0;">
<div style="color: #7F8C8D; font-size: 12px; font-weight: bold; margin-bottom: 8px;">WORD-BY-WORD COMPARISON (${debugExchangeType} exchange)</div>
<table style="width: 100%; border-collapse: collapse; font-size: 13px;">
<tr style="background: #2C3E50; color: white;">
<th style="padding: 6px 8px; text-align: left;">Position</th>
<th style="padding: 6px 8px; text-align: left;">Routing Key</th>
<th style="padding: 6px 8px; text-align: left;">Binding Pattern</th>
<th style="padding: 6px 8px; text-align: left;">Result</th>
</tr>
${debugResult.partComparison.map((c, i) => `
<tr style="background: ${c.status === 'match' ? '#f0faf8' : '#fef5f5'}; border-bottom: 1px solid #e0e0e0;">
<td style="padding: 6px 8px; color: #7F8C8D;">${i + 1}</td>
<td style="padding: 6px 8px; font-family: monospace; font-weight: bold;">${c.rk}</td>
<td style="padding: 6px 8px; font-family: monospace; color: ${c.bk === '*' || c.bk === '#' || c.bk === '(consumed by #)' ? '#E67E22' : '#2C3E50'}; font-weight: bold;">${c.bk}</td>
<td style="padding: 6px 8px; color: ${c.status === 'match' ? '#16A085' : '#E74C3C'}; font-size: 12px;">${c.note}</td>
</tr>
`).join('')}
</table>
</div>
${!debugResult.matches ? '<div style="margin-top: 10px; padding: 8px; background: #fef9e7; border-radius: 4px; font-size: 12px; color: #2C3E50; border-left: 4px solid #E67E22;"><strong>Debugging tip:</strong> Check for typos or abbreviation mismatches (e.g., "temperature" vs "temp"). Use <code>#</code> at the end of a pattern to match variable-depth keys, or <code>*</code> to match exactly one word at a specific position.</div>' : ''}
` : `
<div style="background: white; padding: 12px; border-radius: 4px; border: 1px solid #e0e0e0; font-size: 13px; color: #7F8C8D;">
Direct exchange uses exact string comparison. No word-by-word analysis needed.
</div>
`}
</div>`