viewof exchangeType = Inputs.select(
["direct", "fanout", "topic", "headers"],
{value: "topic", label: "Exchange type:"}
)
viewof routingKey = Inputs.text({
value: "sensor.temperature.floor1",
label: "Routing key:",
placeholder: "e.g., sensor.temperature.floor1",
width: 400
})
viewof sendMessage = Inputs.button("Publish Message")Try It: AMQP Exchange Type Routing Explorer
Try It: AMQP Exchange Type Routing Explorer
animation
amqp
protocols
messaging
Try Change routing key to sensor.temperature.floor1 and select direct.
Observe Watch analytics-queue and alerts-queue after Play routing.
Explain Explain why fanout ignores sensor.temperature.floor1 and delivers to all bound queues.
Technical boundaries. Headers matching is simulated randomly. Topic routing uses the prefix before # and word matching for *.
NoteTry It: AMQP Exchange Type Routing Explorer
Select an exchange type and publish messages with different routing keys to see which queues receive each message. Observe how direct, fanout, topic, and headers exchanges differ in routing behavior.
exchangeColors = ({
navy: "#2C3E50",
teal: "#16A085",
orange: "#E67E22",
blue: "#3498DB",
gray: "#7F8C8D",
purple: "#9B59B6",
red: "#E74C3C"
})
queueBindings = [
{name: "alerts-queue", directKey: "alert.critical", topicPattern: "sensor.temperature.*", header: "priority=high"},
{name: "logging-queue", directKey: "log.info", topicPattern: "sensor.#", header: "format=json"},
{name: "analytics-queue", directKey: "sensor.temperature.floor1", topicPattern: "*.temperature.*", header: "priority=low"},
{name: "archive-queue", directKey: "archive.daily", topicPattern: "sensor.*.floor1", header: "format=json"}
]
routingResults = {
sendMessage;
const key = routingKey;
return queueBindings.map(q => {
let matched = false;
let reason = "";
if (exchangeType === "direct") {
matched = key === q.directKey;
reason = matched ? `Exact match: "${key}" = "${q.directKey}"` : `No match: "${key}" != "${q.directKey}"`;
} else if (exchangeType === "fanout") {
matched = true;
reason = "Fanout delivers to ALL bound queues (routing key ignored)";
} else if (exchangeType === "topic") {
const pattern = q.topicPattern;
const keyParts = key.split(".");
const patParts = pattern.split(".");
if (pattern.includes("#")) {
const prefix = pattern.split("#")[0];
matched = prefix === "" || key.startsWith(prefix.slice(0, -1));
reason = matched ? `"#" wildcard matched: "${key}" starts with "${prefix}"` : `"#" wildcard failed: "${key}" doesn't match "${pattern}"`;
} else if (pattern.includes("*")) {
if (keyParts.length === patParts.length) {
matched = patParts.every((p, i) => p === "*" || p === keyParts[i]);
reason = matched ? `"*" wildcard matched: "${key}" fits "${pattern}"` : `Word count matches but segments differ`;
} else {
reason = `Word count mismatch: ${keyParts.length} vs ${patParts.length} segments`;
}
} else {
matched = key === pattern;
reason = matched ? `Exact topic match` : `No match: "${key}" != "${pattern}"`;
}
} else {
matched = Math.random() > 0.5;
reason = matched ? "Headers matched (simulated)" : "Headers not matched (simulated)";
}
return {...q, matched, reason};
});
}
html`
<div style="background: linear-gradient(135deg, ${exchangeColors.navy} 0%, #1a252f 100%); padding: 25px; border-radius: 12px; color: white; margin: 10px 0; font-family: Arial, sans-serif;">
<div style="display: flex; align-items: center; gap: 12px; margin-bottom: 20px;">
<div style="background: ${exchangeType === 'direct' ? exchangeColors.blue : exchangeType === 'fanout' ? exchangeColors.orange : exchangeType === 'topic' ? exchangeColors.teal : exchangeColors.purple}; padding: 10px 18px; border-radius: 8px; font-weight: bold; font-size: 1.1em;">
${exchangeType.toUpperCase()} Exchange
</div>
<div style="opacity: 0.8;">Routing key: <code style="background: rgba(255,255,255,0.15); padding: 3px 8px; border-radius: 4px;">${routingKey}</code></div>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px;">
${routingResults.map(q => html`
<div style="background: ${q.matched ? 'rgba(22,160,133,0.25)' : 'rgba(231,76,60,0.15)'}; padding: 14px; border-radius: 8px; border-left: 4px solid ${q.matched ? exchangeColors.teal : exchangeColors.red};">
<div style="font-weight: bold; margin-bottom: 6px;">${q.matched ? '>>> ' : '--- '}${q.name}</div>
<div style="font-size: 0.8em; opacity: 0.85; margin-bottom: 4px;">
${exchangeType === 'direct' ? `Binding: "${q.directKey}"` : exchangeType === 'topic' ? `Pattern: "${q.topicPattern}"` : exchangeType === 'headers' ? `Match: ${q.header}` : 'All queues bound'}
</div>
<div style="font-size: 0.78em; opacity: 0.7; font-style: italic;">${q.reason}</div>
</div>
`)}
</div>
<div style="margin-top: 16px; padding: 12px; background: rgba(255,255,255,0.06); border-radius: 8px; font-size: 0.85em; opacity: 0.9;">
<strong>Tip:</strong> ${exchangeType === 'direct' ? 'Direct exchanges require exact key match. Try "sensor.temperature.floor1" or "alert.critical".' : exchangeType === 'fanout' ? 'Fanout ignores the routing key entirely -- every bound queue gets every message. Great for broadcasting.' : exchangeType === 'topic' ? 'Topic patterns: "*" matches one word, "#" matches zero or more. Try "sensor.humidity.floor2" or "alert.critical".' : 'Headers exchanges match on message header attributes rather than routing keys.'}
</div>
</div>
`