viewof selectedExchange = Inputs.radio(
["Direct", "Fanout", "Topic", "Headers"],
{value: "Topic", label: "Select exchange type:"}
)
viewof numQueues = Inputs.range([1, 8], {value: 3, step: 1, label: "Number of bound queues:"})
viewof routingKey = Inputs.text({
value: "sensor.temperature.zone1",
label: "Message routing key:",
placeholder: "e.g. sensor.temperature.zone1"
})Try It: Exchange Type Selector
Try It: Exchange Type Selector
animation
amqp
protocols
messaging
Try Change number of bound queues to 8 and select Topic.
Observe Watch Queues Receiving and Routing Example after Play routing.
Explain Describe how Play routing changes Match Logic when selecting Fanout.
Technical boundaries. Topic and Headers queues receiving use fixed fractions of bound queues. Direct always shows one queue receiving.
NoteTry It: Exchange Type Selector
exchangeInfo = {
const info = {
"Direct": {
color: "#3498DB",
description: "Exact match only. The routing key must exactly equal the binding key.",
matchLogic: "Exact string comparison",
queuesReceiving: 1,
bestFor: "Task queues, RPC, point-to-point messaging",
performance: "Fastest (O(1) hash lookup)",
example: `Routing key "${routingKey}" matches only a queue bound with exactly "${routingKey}".`
},
"Fanout": {
color: "#E67E22",
description: "Broadcast to ALL bound queues. The routing key is completely ignored.",
matchLogic: "No matching needed - all queues receive",
queuesReceiving: numQueues,
bestFor: "Notifications, audit logging, event broadcasting",
performance: "Fast (simple copy to N queues)",
example: `Routing key "${routingKey}" is ignored. All ${numQueues} bound queues receive the message.`
},
"Topic": {
color: "#16A085",
description: "Wildcard pattern matching on dot-separated routing keys. Use * for one word, # for zero or more.",
matchLogic: "Pattern matching with * and # wildcards",
queuesReceiving: Math.min(numQueues, Math.max(1, Math.ceil(numQueues * 0.6))),
bestFor: "IoT sensor routing, geographic filtering, hierarchical data",
performance: "Medium (pattern evaluation per binding)",
example: `Routing key "${routingKey}" is matched against patterns like "${routingKey.split('.').slice(0, -1).join('.')}.*" or "${routingKey.split('.')[0]}.#".`
},
"Headers": {
color: "#9B59B6",
description: "Routes based on message header attributes instead of routing key. Supports x-match: all (AND) or any (OR).",
matchLogic: "Header attribute comparison (AND/OR logic)",
queuesReceiving: Math.min(numQueues, Math.max(1, Math.ceil(numQueues * 0.4))),
bestFor: "Complex multi-attribute routing, content-based decisions",
performance: "Slowest (multi-attribute evaluation)",
example: `Routing key "${routingKey}" is ignored. Headers like {sensor: "temperature", zone: "1"} determine routing.`
}
};
return info[selectedExchange];
}
html`<div style="background: #f8f9fa; border-left: 4px solid ${exchangeInfo.color}; padding: 15px; margin-top: 15px; font-family: Arial, sans-serif;">
<h4 style="color: ${exchangeInfo.color}; margin-top: 0;">${selectedExchange} Exchange</h4>
<p style="color: #2C3E50; margin: 8px 0; font-size: 14px;">${exchangeInfo.description}</p>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px;">
<div style="background: white; padding: 10px; border-radius: 4px; border: 1px solid #e0e0e0;">
<div style="color: #7F8C8D; font-size: 11px; text-transform: uppercase;">Match Logic</div>
<div style="color: #2C3E50; font-size: 14px; font-weight: bold; margin-top: 4px;">${exchangeInfo.matchLogic}</div>
</div>
<div style="background: white; padding: 10px; border-radius: 4px; border: 1px solid #e0e0e0;">
<div style="color: #7F8C8D; font-size: 11px; text-transform: uppercase;">Queues Receiving</div>
<div style="color: ${exchangeInfo.color}; font-size: 24px; font-weight: bold; margin-top: 4px;">${exchangeInfo.queuesReceiving} / ${numQueues}</div>
</div>
<div style="background: white; padding: 10px; border-radius: 4px; border: 1px solid #e0e0e0;">
<div style="color: #7F8C8D; font-size: 11px; text-transform: uppercase;">Performance</div>
<div style="color: #2C3E50; font-size: 14px; font-weight: bold; margin-top: 4px;">${exchangeInfo.performance}</div>
</div>
<div style="background: white; padding: 10px; border-radius: 4px; border: 1px solid #e0e0e0;">
<div style="color: #7F8C8D; font-size: 11px; text-transform: uppercase;">Best For</div>
<div style="color: #2C3E50; font-size: 14px; margin-top: 4px;">${exchangeInfo.bestFor}</div>
</div>
</div>
<div style="margin-top: 12px; padding: 10px; background: white; border-radius: 4px; border: 1px solid #e0e0e0;">
<div style="color: #7F8C8D; font-size: 11px; text-transform: uppercase; margin-bottom: 4px;">Routing Example</div>
<div style="color: #2C3E50; font-size: 13px;">${exchangeInfo.example}</div>
</div>
<div style="margin-top: 12px; display: flex; gap: 4px; align-items: center;">
${Array.from({length: numQueues}, (_, i) => {
const receiving = i < exchangeInfo.queuesReceiving;
return `<div style="flex: 1; height: 32px; border-radius: 4px; background: ${receiving ? exchangeInfo.color : '#e0e0e0'}; display: flex; align-items: center; justify-content: center; color: ${receiving ? 'white' : '#7F8C8D'}; font-size: 11px; font-weight: bold;">Q${i + 1}</div>`;
}).join('')}
</div>
<div style="color: #7F8C8D; font-size: 11px; margin-top: 4px; text-align: center;">Queue delivery visualization (green = receives message)</div>
</div>`